Skip to content

Commit ec752ae

Browse files
committed
Minor refactoring wrt Records
1 parent d923bb1 commit ec752ae

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/BeanPropertyIntrospector.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.fasterxml.jackson.jr.ob.impl;
22

33
import java.lang.reflect.*;
4-
import java.util.HashMap;
5-
import java.util.Map;
6-
import java.util.TreeMap;
4+
import java.util.*;
75

86
import com.fasterxml.jackson.jr.ob.JSON;
97
import com.fasterxml.jackson.jr.ob.impl.POJODefinition.Prop;
@@ -30,11 +28,13 @@ public BeanPropertyIntrospector() { }
3028
public static BeanPropertyIntrospector instance() { return INSTANCE; }
3129

3230
public POJODefinition pojoDefinitionForDeserialization(JSONReader r, Class<?> pojoType) {
33-
return _introspectDefinition(pojoType, false, r.features());
31+
return _introspectDefinition(pojoType, false, r.features(),
32+
RecordsHelpers.isRecordType(pojoType));
3433
}
3534

3635
public POJODefinition pojoDefinitionForSerialization(JSONWriter w, Class<?> pojoType) {
37-
return _introspectDefinition(pojoType, true, w.features());
36+
return _introspectDefinition(pojoType, true, w.features(),
37+
RecordsHelpers.isRecordType(pojoType));
3838
}
3939

4040
/*
@@ -44,18 +44,18 @@ public POJODefinition pojoDefinitionForSerialization(JSONWriter w, Class<?> pojo
4444
*/
4545

4646
private POJODefinition _introspectDefinition(Class<?> beanType,
47-
boolean forSerialization, int features)
47+
boolean forSerialization, int features, boolean isRecord)
4848
{
4949
Map<String,PropBuilder> propsByName = new TreeMap<>();
50-
_introspect(beanType, propsByName, features);
50+
_introspect(beanType, propsByName, features, isRecord);
5151

5252
final BeanConstructors constructors;
5353

5454
if (forSerialization) {
5555
constructors = null;
5656
} else {
5757
constructors = new BeanConstructors(beanType);
58-
if (RecordsHelpers.isRecordType(beanType)) {
58+
if (isRecord) {
5959
Constructor<?> canonical = RecordsHelpers.findCanonicalConstructor(beanType);
6060
if (canonical == null) { // should never happen
6161
throw new IllegalArgumentException(
@@ -96,22 +96,22 @@ private POJODefinition _introspectDefinition(Class<?> beanType,
9696
}
9797

9898
private static void _introspect(Class<?> currType, Map<String, PropBuilder> props,
99-
int features)
99+
int features, boolean isRecord)
100100
{
101101
if (currType == null || currType == Object.class) {
102102
return;
103103
}
104104
// First, check base type
105-
_introspect(currType.getSuperclass(), props, features);
105+
_introspect(currType.getSuperclass(), props, features, isRecord);
106106

107107
final boolean noStatics = JSON.Feature.INCLUDE_STATIC_FIELDS.isDisabled(features);
108108

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

114-
final Map<String, Field> fieldNameMap = isFieldNameGettersEnabled ? new HashMap<>() : null;
114+
final Map<String, Field> fieldNameMap = isFieldNameGettersEnabled ? new LinkedHashMap<>() : null;
115115

116116
// then public fields (since 2.8); may or may not be ultimately included
117117
// but at this point still possible

0 commit comments

Comments
 (0)