From 5063d314a553f79e89a7473e1bc9b3d6438168a6 Mon Sep 17 00:00:00 2001 From: Simulant Date: Wed, 25 Jun 2025 23:08:01 +0200 Subject: [PATCH] #984 extract method for annotation value check --- src/main/java/org/json/JSONObject.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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