Skip to content

Commit

Permalink
Fix the NPE issue
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jun 14, 2024
1 parent 03d6f13 commit 49f5983
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ private static void _introspect(Class<?> currType, Map<String, PropBuilder> prop
_introspect(currType.getSuperclass(), props, features);

final boolean noStatics = JSON.Feature.INCLUDE_STATIC_FIELDS.isDisabled(features);
final boolean isFieldNameGettersEnabled = JSON.Feature.USE_FIELD_MATCHING_GETTERS.isEnabled(features);

// 14-Jun-2024, tatu: Need to enable "matching getters" naming style for Java Records
// too, regardless of `Feature.USE_FIELD_MATCHING_GETTERS`
final boolean isFieldNameGettersEnabled = JSON.Feature.USE_FIELD_MATCHING_GETTERS.isEnabled(features)
|| RecordsHelpers.isRecordType(currType);

final Map<String, Field> fieldNameMap = isFieldNameGettersEnabled ? new HashMap<>() : null;

Expand Down Expand Up @@ -150,14 +154,15 @@ private static void _introspect(Class<?> currType, Map<String, PropBuilder> prop
name = decap(name.substring(2));
_propFrom(props, name).withIsGetter(m);
}
} else if(RecordsHelpers.isRecordType(currType) || isFieldNameGettersEnabled){
} else if (isFieldNameGettersEnabled){
// 10-Mar-2024: [jackson-jr#94]:
// This will allow getters with field name as their getters,
// like the ones generated by Groovy (or JDK 17 for Records).
// If method name matches with field name, & method return
// type matches the field type only then it can be considered a getter.
Field field = fieldNameMap.get(name);
if (field != null && Modifier.isPublic(m.getModifiers()) && m.getReturnType().equals(field.getType())) {
if (field != null && Modifier.isPublic(m.getModifiers())
&& m.getReturnType().equals(field.getType())) {
// NOTE: do NOT decap, field name should be used as-is
_propFrom(props, name).withGetter(m);
}
Expand Down

0 comments on commit 49f5983

Please sign in to comment.