diff options
author | Carsten Lund <lund@research.att.com> | 2017-05-02 02:05:12 +0000 |
---|---|---|
committer | Carsten Lund <lund@research.att.com> | 2017-05-02 02:05:12 +0000 |
commit | 03f9567726dfa0c6af315d88c316be9cb380d8ae (patch) | |
tree | f3602aeb53078b955ccb4a4f06220a0cc753e228 /ncomp-utils-java/src/main/java/org/json/JSONObject.java | |
parent | f096d31080e5a62120d6536681a0859d2202c717 (diff) |
[DCAE-15] Changes related to version 1.1 (2)
Change-Id: I3537af308ff9c7d6faebad4b5faee53890d03c9e
Signed-off-by: Carsten Lund <lund@research.att.com>
Diffstat (limited to 'ncomp-utils-java/src/main/java/org/json/JSONObject.java')
-rw-r--r-- | ncomp-utils-java/src/main/java/org/json/JSONObject.java | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/ncomp-utils-java/src/main/java/org/json/JSONObject.java b/ncomp-utils-java/src/main/java/org/json/JSONObject.java index 4795082..7e2b9a6 100644 --- a/ncomp-utils-java/src/main/java/org/json/JSONObject.java +++ b/ncomp-utils-java/src/main/java/org/json/JSONObject.java @@ -140,6 +140,10 @@ public class JSONObject { public boolean equals(Object object) { return object == null || object == this; } + @Override + public int hashCode() { + return super.hashCode(); + } /** @@ -351,39 +355,39 @@ public class JSONObject { Method method = methods[i]; if (Modifier.isPublic(method.getModifiers())) { String name = method.getName(); - String key = ""; + String k = ""; if (name.startsWith("get")) { - key = name.substring(3); + k = name.substring(3); } else if (name.startsWith("is")) { - key = name.substring(2); + k = name.substring(2); } - if (key.length() > 0 && - Character.isUpperCase(key.charAt(0)) && + if (k.length() > 0 && + Character.isUpperCase(k.charAt(0)) && method.getParameterTypes().length == 0) { - if (key.length() == 1) { - key = key.toLowerCase(); - } else if (!Character.isUpperCase(key.charAt(1))) { - key = key.substring(0, 1).toLowerCase() + - key.substring(1); + if (k.length() == 1) { + k = k.toLowerCase(); + } else if (!Character.isUpperCase(k.charAt(1))) { + k = k.substring(0, 1).toLowerCase() + + k.substring(1); } Object result = method.invoke(bean, (Object[])null); if (result == null) { - map.put(key, NULL); + map.put(k, NULL); } else if (result.getClass().isArray()) { - map.put(key, new JSONArray(result, includeSuperClass)); + map.put(k, new JSONArray(result, includeSuperClass)); } else if (result instanceof Collection) { // List or Set - map.put(key, new JSONArray((Collection<?>)result, includeSuperClass)); + map.put(k, new JSONArray((Collection<?>)result, includeSuperClass)); } else if (result instanceof Map) { - map.put(key, new JSONObject((Map<?, ?>)result, includeSuperClass)); + map.put(k, new JSONObject((Map<?, ?>)result, includeSuperClass)); } else if (isStandardProperty(result.getClass())) { // Primitives, String and Wrapper - map.put(key, result); + map.put(k, result); } else { if (result.getClass().getPackage().getName().startsWith("java") || result.getClass().getClassLoader() == null) { - map.put(key, result.toString()); + map.put(k, result.toString()); } else { // User defined Objects - map.put(key, new JSONObject(result, includeSuperClass)); + map.put(k, new JSONObject(result, includeSuperClass)); } } } |