Skip to content

Commit

Permalink
Merge branch '2.19'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Oct 21, 2024
2 parents 17ed10f + 1cd8b4a commit d6770bb
Showing 1 changed file with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package tools.jackson.jr.ob.impl;

import java.lang.reflect.*;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import java.util.*;

import tools.jackson.jr.ob.JSON;
import tools.jackson.jr.ob.impl.POJODefinition.Prop;
Expand All @@ -28,11 +26,13 @@ public BeanPropertyIntrospector() { }
public static BeanPropertyIntrospector instance() { return INSTANCE; }

public POJODefinition pojoDefinitionForDeserialization(JSONReader r, Class<?> pojoType) {
return _introspectDefinition(pojoType, false, r.features());
return _introspectDefinition(pojoType, false, r.features(),
RecordsHelpers.isRecordType(pojoType));
}

public POJODefinition pojoDefinitionForSerialization(JSONWriter w, Class<?> pojoType) {
return _introspectDefinition(pojoType, true, w.features());
return _introspectDefinition(pojoType, true, w.features(),
RecordsHelpers.isRecordType(pojoType));
}

/*
Expand All @@ -42,18 +42,18 @@ public POJODefinition pojoDefinitionForSerialization(JSONWriter w, Class<?> pojo
*/

private POJODefinition _introspectDefinition(Class<?> beanType,
boolean forSerialization, int features)
boolean forSerialization, int features, boolean isRecord)
{
Map<String,PropBuilder> propsByName = new TreeMap<>();
_introspect(beanType, propsByName, features);
_introspect(beanType, propsByName, features, isRecord);

final BeanConstructors constructors;

if (forSerialization) {
constructors = null;
} else {
constructors = new BeanConstructors(beanType);
if (RecordsHelpers.isRecordType(beanType)) {
if (isRecord) {
Constructor<?> canonical = RecordsHelpers.findCanonicalConstructor(beanType);
if (canonical == null) { // should never happen
throw new IllegalArgumentException(
Expand Down Expand Up @@ -94,22 +94,22 @@ private POJODefinition _introspectDefinition(Class<?> beanType,
}

private static void _introspect(Class<?> currType, Map<String, PropBuilder> props,
int features)
int features, boolean isRecord)
{
if (currType == null || currType == Object.class) {
return;
}
// First, check base type
_introspect(currType.getSuperclass(), props, features);
_introspect(currType.getSuperclass(), props, features, isRecord);

final boolean noStatics = JSON.Feature.INCLUDE_STATIC_FIELDS.isDisabled(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 boolean isFieldNameGettersEnabled = isRecord
|| JSON.Feature.USE_FIELD_MATCHING_GETTERS.isEnabled(features);

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

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

0 comments on commit d6770bb

Please sign in to comment.