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