1
1
package tools .jackson .jr .ob .impl ;
2
2
3
3
import java .lang .reflect .*;
4
- import java .util .HashMap ;
5
- import java .util .Map ;
6
- import java .util .TreeMap ;
4
+ import java .util .*;
7
5
8
6
import tools .jackson .jr .ob .JSON ;
9
7
import tools .jackson .jr .ob .impl .POJODefinition .Prop ;
@@ -28,11 +26,13 @@ public BeanPropertyIntrospector() { }
28
26
public static BeanPropertyIntrospector instance () { return INSTANCE ; }
29
27
30
28
public POJODefinition pojoDefinitionForDeserialization (JSONReader r , Class <?> pojoType ) {
31
- return _introspectDefinition (pojoType , false , r .features ());
29
+ return _introspectDefinition (pojoType , false , r .features (),
30
+ RecordsHelpers .isRecordType (pojoType ));
32
31
}
33
32
34
33
public POJODefinition pojoDefinitionForSerialization (JSONWriter w , Class <?> pojoType ) {
35
- return _introspectDefinition (pojoType , true , w .features ());
34
+ return _introspectDefinition (pojoType , true , w .features (),
35
+ RecordsHelpers .isRecordType (pojoType ));
36
36
}
37
37
38
38
/*
@@ -42,18 +42,18 @@ public POJODefinition pojoDefinitionForSerialization(JSONWriter w, Class<?> pojo
42
42
*/
43
43
44
44
private POJODefinition _introspectDefinition (Class <?> beanType ,
45
- boolean forSerialization , int features )
45
+ boolean forSerialization , int features , boolean isRecord )
46
46
{
47
47
Map <String ,PropBuilder > propsByName = new TreeMap <>();
48
- _introspect (beanType , propsByName , features );
48
+ _introspect (beanType , propsByName , features , isRecord );
49
49
50
50
final BeanConstructors constructors ;
51
51
52
52
if (forSerialization ) {
53
53
constructors = null ;
54
54
} else {
55
55
constructors = new BeanConstructors (beanType );
56
- if (RecordsHelpers . isRecordType ( beanType ) ) {
56
+ if (isRecord ) {
57
57
Constructor <?> canonical = RecordsHelpers .findCanonicalConstructor (beanType );
58
58
if (canonical == null ) { // should never happen
59
59
throw new IllegalArgumentException (
@@ -94,22 +94,22 @@ private POJODefinition _introspectDefinition(Class<?> beanType,
94
94
}
95
95
96
96
private static void _introspect (Class <?> currType , Map <String , PropBuilder > props ,
97
- int features )
97
+ int features , boolean isRecord )
98
98
{
99
99
if (currType == null || currType == Object .class ) {
100
100
return ;
101
101
}
102
102
// First, check base type
103
- _introspect (currType .getSuperclass (), props , features );
103
+ _introspect (currType .getSuperclass (), props , features , isRecord );
104
104
105
105
final boolean noStatics = JSON .Feature .INCLUDE_STATIC_FIELDS .isDisabled (features );
106
106
107
107
// 14-Jun-2024, tatu: Need to enable "matching getters" naming style for Java Records
108
108
// too, regardless of `Feature.USE_FIELD_MATCHING_GETTERS`
109
- final boolean isFieldNameGettersEnabled = JSON . Feature . USE_FIELD_MATCHING_GETTERS . isEnabled ( features )
110
- || RecordsHelpers . isRecordType ( currType );
109
+ final boolean isFieldNameGettersEnabled = isRecord
110
+ || JSON . Feature . USE_FIELD_MATCHING_GETTERS . isEnabled ( features );
111
111
112
- final Map <String , Field > fieldNameMap = isFieldNameGettersEnabled ? new HashMap <>() : null ;
112
+ final Map <String , Field > fieldNameMap = isFieldNameGettersEnabled ? new LinkedHashMap <>() : null ;
113
113
114
114
// then public fields (since 2.8); may or may not be ultimately included
115
115
// but at this point still possible
0 commit comments