mirror of
https://github.com/ethauvin/JSON-java.git
synced 2025-06-17 07:50:52 -07:00
Adds check for resources opened by our bean mapping
This commit is contained in:
parent
641b68dd55
commit
a129ebe8e4
1 changed files with 16 additions and 3 deletions
|
@ -1,5 +1,7 @@
|
||||||
package org.json;
|
package org.json;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright (c) 2002 JSON.org
|
Copyright (c) 2002 JSON.org
|
||||||
|
|
||||||
|
@ -1412,8 +1414,10 @@ public class JSONObject {
|
||||||
.getDeclaredMethods();
|
.getDeclaredMethods();
|
||||||
for (final Method method : methods) {
|
for (final Method method : methods) {
|
||||||
final int modifiers = method.getModifiers();
|
final int modifiers = method.getModifiers();
|
||||||
if (Modifier.isPublic(modifiers) && !Modifier.isStatic(modifiers)
|
if (Modifier.isPublic(modifiers)
|
||||||
&& method.getParameterTypes().length == 0 && !method.isBridge()
|
&& !Modifier.isStatic(modifiers)
|
||||||
|
&& method.getParameterTypes().length == 0
|
||||||
|
&& !method.isBridge()
|
||||||
&& method.getReturnType() != Void.TYPE ) {
|
&& method.getReturnType() != Void.TYPE ) {
|
||||||
final String name = method.getName();
|
final String name = method.getName();
|
||||||
String key;
|
String key;
|
||||||
|
@ -1427,7 +1431,8 @@ public class JSONObject {
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (key.length() > 0 && Character.isUpperCase(key.charAt(0))) {
|
if (key.length() > 0
|
||||||
|
&& Character.isUpperCase(key.charAt(0))) {
|
||||||
if (key.length() == 1) {
|
if (key.length() == 1) {
|
||||||
key = key.toLowerCase(Locale.ROOT);
|
key = key.toLowerCase(Locale.ROOT);
|
||||||
} else if (!Character.isUpperCase(key.charAt(1))) {
|
} else if (!Character.isUpperCase(key.charAt(1))) {
|
||||||
|
@ -1439,6 +1444,14 @@ public class JSONObject {
|
||||||
final Object result = method.invoke(bean);
|
final Object result = method.invoke(bean);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
this.map.put(key, wrap(result));
|
this.map.put(key, wrap(result));
|
||||||
|
// we don't use the result anywhere outside of wrap
|
||||||
|
// if it's a resource we should be sure to close it after calling toString
|
||||||
|
if(result instanceof Closeable) {
|
||||||
|
try {
|
||||||
|
((Closeable)result).close();
|
||||||
|
} catch (IOException ignore) {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (IllegalAccessException ignore) {
|
} catch (IllegalAccessException ignore) {
|
||||||
} catch (IllegalArgumentException ignore) {
|
} catch (IllegalArgumentException ignore) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue