diff --git a/jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/BeanPropertyIntrospector.java b/jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/BeanPropertyIntrospector.java index f9ee13b1..1a138515 100644 --- a/jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/BeanPropertyIntrospector.java +++ b/jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/BeanPropertyIntrospector.java @@ -98,7 +98,11 @@ private static void _introspect(Class currType, Map 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 fieldNameMap = isFieldNameGettersEnabled ? new HashMap<>() : null; @@ -150,14 +154,15 @@ private static void _introspect(Class currType, Map 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); }