tech-debt-25250701 add jacoco to gradle build, refactor JSONObject to restore performance

This commit is contained in:
Sean Leary 2025-07-03 20:39:13 -05:00
parent 197afddbfb
commit 7b0d1942b4
2 changed files with 37 additions and 27 deletions

View File

@ -3,9 +3,10 @@
*/ */
apply plugin: 'java' apply plugin: 'java'
apply plugin: 'eclipse' apply plugin: 'eclipse'
// apply plugin: 'jacoco' apply plugin: 'jacoco'
apply plugin: 'maven-publish' apply plugin: 'maven-publish'
// for now, publishing to maven is still a manual process
//plugins { //plugins {
// id 'java' // id 'java'
//id 'maven-publish' //id 'maven-publish'
@ -19,6 +20,17 @@ repositories {
} }
} }
// To view the report open build/reports/jacoco/test/html/index.html
jacocoTestReport {
reports {
html.required = true
}
}
test {
finalizedBy jacocoTestReport
}
dependencies { dependencies {
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
testImplementation 'com.jayway.jsonpath:json-path:2.9.0' testImplementation 'com.jayway.jsonpath:json-path:2.9.0'

View File

@ -1780,30 +1780,32 @@ public class JSONObject {
Method[] methods = includeSuperClass ? klass.getMethods() : klass.getDeclaredMethods(); Method[] methods = includeSuperClass ? klass.getMethods() : klass.getDeclaredMethods();
for (final Method method : methods) { for (final Method method : methods) {
final String key = getKeyNameFromMethod(method); if (isValidMethod(method)) {
if (key != null && !key.isEmpty()) { final String key = getKeyNameFromMethod(method);
try { if (key != null && !key.isEmpty()) {
final Object result = method.invoke(bean); try {
if (result != null || jsonParserConfiguration.isUseNativeNulls()) { final Object result = method.invoke(bean);
// check cyclic dependency and throw error if needed if (result != null || jsonParserConfiguration.isUseNativeNulls()) {
// the wrap and populateMap combination method is // check cyclic dependency and throw error if needed
// itself DFS recursive // the wrap and populateMap combination method is
if (objectsRecord.contains(result)) { // itself DFS recursive
throw recursivelyDefinedObjectException(key); if (objectsRecord.contains(result)) {
throw recursivelyDefinedObjectException(key);
}
objectsRecord.add(result);
testValidity(result);
this.map.put(key, wrap(result, objectsRecord));
objectsRecord.remove(result);
closeClosable(result);
} }
} catch (IllegalAccessException ignore) {
objectsRecord.add(result); } catch (IllegalArgumentException ignore) {
} catch (InvocationTargetException ignore) {
testValidity(result);
this.map.put(key, wrap(result, objectsRecord));
objectsRecord.remove(result);
closeClosable(result);
} }
} catch (IllegalAccessException ignore) {
} catch (IllegalArgumentException ignore) {
} catch (InvocationTargetException ignore) {
} }
} }
} }
@ -1814,10 +1816,6 @@ public class JSONObject {
} }
private static String getKeyNameFromMethod(Method method) { private static String getKeyNameFromMethod(Method method) {
if (!isValidMethod(method)) {
return null;
}
final int ignoreDepth = getAnnotationDepth(method, JSONPropertyIgnore.class); final int ignoreDepth = getAnnotationDepth(method, JSONPropertyIgnore.class);
if (ignoreDepth > 0) { if (ignoreDepth > 0) {
final int forcedNameDepth = getAnnotationDepth(method, JSONPropertyName.class); final int forcedNameDepth = getAnnotationDepth(method, JSONPropertyName.class);