diff --git a/src/main/java/org/json/JSONObject.java b/src/main/java/org/json/JSONObject.java index 985335e..7b81157 100644 --- a/src/main/java/org/json/JSONObject.java +++ b/src/main/java/org/json/JSONObject.java @@ -1828,7 +1828,7 @@ public class JSONObject { } } JSONPropertyName annotation = getAnnotation(method, JSONPropertyName.class); - if (annotation != null && annotation.value() != null && !annotation.value().isEmpty()) { + if (annotationValueNotEmpty(annotation)) { return annotation.value(); } String key; @@ -1854,6 +1854,15 @@ public class JSONObject { return key; } + /** + * checks if the annotation is not null and the {@link JSONPropertyName#value()} is not null and is not empty. + * @param annotation the annotation to check + * @return true if the annotation and the value is not null and not empty, false otherwise. + */ + private static boolean annotationValueNotEmpty(JSONPropertyName annotation) { + return annotation != null && annotation.value() != null && !annotation.value().isEmpty(); + } + /** * Checks if the method is valid for the {@link #populateMap(Object, Set, JSONParserConfiguration)} use case * @param method the Method to check