@@ -61,6 +61,11 @@ public class POJOPropertiesCollector
61
61
*/
62
62
protected final boolean _useAnnotations ;
63
63
64
+ /**
65
+ * @since 2.15
66
+ */
67
+ protected final boolean _isRecordType ;
68
+
64
69
/*
65
70
/**********************************************************
66
71
/* Collected property information
@@ -170,6 +175,7 @@ protected POJOPropertiesCollector(MapperConfig<?> config, boolean forSerializati
170
175
_forSerialization = forSerialization ;
171
176
_type = type ;
172
177
_classDef = classDef ;
178
+ _isRecordType = _type .isRecordType ();
173
179
if (config .isAnnotationProcessingEnabled ()) {
174
180
_useAnnotations = true ;
175
181
_annotationIntrospector = _config .getAnnotationIntrospector ();
@@ -225,7 +231,7 @@ public JavaType getType() {
225
231
* @since 2.15
226
232
*/
227
233
public boolean isRecordType () {
228
- return _type . isRecordType () ;
234
+ return _isRecordType ;
229
235
}
230
236
231
237
public AnnotatedClass getClassDef () {
@@ -431,7 +437,12 @@ protected void collectAll()
431
437
LinkedHashMap <String , POJOPropertyBuilder > props = new LinkedHashMap <String , POJOPropertyBuilder >();
432
438
433
439
// First: gather basic data
434
- _addFields (props ); // note: populates _fieldRenameMappings
440
+
441
+ // 15-Jan-2023, tatu: [databind#3736] Let's avoid detecting fields of Records
442
+ // altogether (unless we find a good reason to detect them)
443
+ if (!isRecordType ()) {
444
+ _addFields (props ); // note: populates _fieldRenameMappings
445
+ }
435
446
_addMethods (props );
436
447
// 25-Jan-2016, tatu: Avoid introspecting (constructor-)creators for non-static
437
448
// inner classes, see [databind#1502]
@@ -994,7 +1005,10 @@ protected void _removeUnwantedProperties(Map<String, POJOPropertyBuilder> props)
994
1005
*/
995
1006
protected void _removeUnwantedAccessor (Map <String , POJOPropertyBuilder > props )
996
1007
{
997
- final boolean inferMutators = _config .isEnabled (MapperFeature .INFER_PROPERTY_MUTATORS );
1008
+ // 15-Jan-2023, tatu: Avoid pulling in mutators for Records; Fields mostly
1009
+ // since there should not be setters.
1010
+ final boolean inferMutators = !isRecordType ()
1011
+ && _config .isEnabled (MapperFeature .INFER_PROPERTY_MUTATORS );
998
1012
Iterator <POJOPropertyBuilder > it = props .values ().iterator ();
999
1013
1000
1014
while (it .hasNext ()) {
0 commit comments