Skip to content

Commit

Permalink
Fixing Test + Minor Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Shounaks committed Mar 7, 2024
1 parent 896293c commit 9c1a34e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;

import com.fasterxml.jackson.jr.ob.impl.POJODefinition.Prop;
Expand Down Expand Up @@ -136,33 +135,30 @@ private static void _introspect(Class<?> currType, Map<String, PropBuilder> prop
continue;
}

Class<?> resultType = m.getReturnType();
if (resultType == Void.class) {
if ( m.getReturnType() == Void.class) {
continue;
}
String name = m.getName();

final String name = m.getName();
if (name.startsWith("get")) {
if (name.length() > 3) {
name = decap(name.substring(3));
_propFrom(props, name).withGetter(m);
_propFrom(props, decap(name.substring(3))).withGetter(m);
}
} else if (name.startsWith("is")) {
if (name.length() > 2) {
// May or may not be used, but collect for now all the same:
name = decap(name.substring(2));
_propFrom(props, name).withIsGetter(m);
_propFrom(props, decap(name.substring(2))).withIsGetter(m);
}
}
else if (isFieldNameGettersEnabled) {
// This will allow getters with field name as their getters, like the ones generated by Groovy
// If method name matches with field name, & method return type matches with field type
// only then it can be considered a direct name getter.
Optional<Field> field = Arrays.stream(currType.getDeclaredFields())
Arrays.stream(currType.getDeclaredFields())
.filter(f -> f.getName().equals(m.getName()))
.findFirst();
if (field.isPresent() && m.getReturnType().equals(field.get().getType())) {
_propFrom(props, decap(name)).withGetter(m);
}
.filter(f -> Modifier.isPublic(m.getModifiers()) && m.getReturnType().equals(f.getType()))
.findFirst()
.ifPresent(f -> _propFrom(props, decap(name)).withGetter(m));
}
} else if (argTypes.length == 1) { // setter?
// Non-public setters are fine if we can force access, don't yet check
Expand Down
5 changes: 5 additions & 0 deletions jr-test-module/src/test/groovy/GroovyObjectSupportTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import com.fasterxml.jackson.jr.ob.JSON
import org.junit.Assert
import org.junit.Test

/**
* A minor note on running/debugging this test on local, if you are using intellij, please
* change `<packaging>pom</packaging>` to `<packaging>bundle</packaging>`. this is causing
* some issue with the IDE.
*/
class GroovyObjectSupportTest {
@Test
void testSimpleGroovyObject() throws Exception {
Expand Down

0 comments on commit 9c1a34e

Please sign in to comment.