Skip to content

Commit 5063d31

Browse files
committed
stleary#984 extract method for annotation value check
1 parent 916fba5 commit 5063d31

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/main/java/org/json/JSONObject.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1828,7 +1828,7 @@ private static String getKeyNameFromMethod(Method method) {
18281828
}
18291829
}
18301830
JSONPropertyName annotation = getAnnotation(method, JSONPropertyName.class);
1831-
if (annotation != null && annotation.value() != null && !annotation.value().isEmpty()) {
1831+
if (annotationValueNotEmpty(annotation)) {
18321832
return annotation.value();
18331833
}
18341834
String key;
@@ -1854,6 +1854,15 @@ private static String getKeyNameFromMethod(Method method) {
18541854
return key;
18551855
}
18561856

1857+
/**
1858+
* checks if the annotation is not null and the {@link JSONPropertyName#value()} is not null and is not empty.
1859+
* @param annotation the annotation to check
1860+
* @return true if the annotation and the value is not null and not empty, false otherwise.
1861+
*/
1862+
private static boolean annotationValueNotEmpty(JSONPropertyName annotation) {
1863+
return annotation != null && annotation.value() != null && !annotation.value().isEmpty();
1864+
}
1865+
18571866
/**
18581867
* Checks if the method is valid for the {@link #populateMap(Object, Set, JSONParserConfiguration)} use case
18591868
* @param method the Method to check

0 commit comments

Comments
 (0)