Skip to content

Commit b3b180a

Browse files
committed
Some more code clean up
1 parent 6be5069 commit b3b180a

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

src/main/java/com/fasterxml/jackson/databind/BeanDescription.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ protected BeanDescription(JavaType type) {
5252

5353
public Class<?> getBeanClass() { return _type.getRawClass(); }
5454

55+
/**
56+
* @since 2.15
57+
*/
58+
public boolean isRecordType() { return _type.isRecordType(); }
59+
5560
/**
5661
* @since 2.9
5762
*/

src/main/java/com/fasterxml/jackson/databind/deser/BasicDeserializerFactory.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import com.fasterxml.jackson.databind.exc.InvalidDefinitionException;
2525
import com.fasterxml.jackson.databind.ext.OptionalHandlerFactory;
2626
import com.fasterxml.jackson.databind.introspect.*;
27-
import com.fasterxml.jackson.databind.jdk14.JDK14Util;
2827
import com.fasterxml.jackson.databind.jsontype.NamedType;
2928
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
3029
import com.fasterxml.jackson.databind.jsontype.TypeResolverBuilder;
@@ -540,9 +539,9 @@ protected void _addImplicitConstructorCreators(DeserializationContext ctxt,
540539
JacksonInject.Value injectable = intr.findInjectableValue(param);
541540
final PropertyName name = (propDef == null) ? null : propDef.getFullName();
542541

543-
if (propDef != null
544-
// NOTE: Record canonical constructor will have implicitly named propDef
545-
&& (propDef.isExplicitlyNamed() || beanDesc.getType().isRecordType())) {
542+
if ((propDef != null)
543+
// [databind#3724]: Record canonical constructor will have implicitly named propDef
544+
&& (propDef.isExplicitlyNamed() || beanDesc.isRecordType())) {
546545
++explicitNameCount;
547546
properties[i] = constructCreatorProperty(ctxt, beanDesc, name, i, param, injectable);
548547
continue;

src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializer.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -466,12 +466,11 @@ protected Object _deserializeUsingPropertyBased(final JsonParser p, final Deseri
466466
}
467467
// regular property? needs buffering
468468
SettableBeanProperty prop = _beanProperties.find(propName);
469-
// Special handling because Records' ignored creator props weren't removed (to help in creating
470-
// constructor-backed PropertyCreator) so they ended up in _beanProperties, unlike POJO (whose ignored
469+
// [databind#3724]: Special handling because Records' ignored creator props
470+
// weren't removed (to help in creating constructor-backed PropertyCreator)
471+
// so they ended up in _beanProperties, unlike POJO (whose ignored
471472
// props are removed)
472-
boolean isClassWithoutMutator = _beanType.isRecordType();
473-
474-
if (prop != null && !isClassWithoutMutator) {
473+
if ((prop != null) && !_beanType.isRecordType()) {
475474
try {
476475
buffer.bufferProperty(prop, _deserializeWithErrorWrapping(p, ctxt, prop));
477476
} catch (UnresolvedForwardReference reference) {

src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertiesCollector.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,14 @@ public MapperConfig<?> getConfig() {
220220
public JavaType getType() {
221221
return _type;
222222
}
223-
223+
224+
/**
225+
* @since 2.15
226+
*/
227+
public boolean isRecordType() {
228+
return _type.isRecordType();
229+
}
230+
224231
public AnnotatedClass getClassDef() {
225232
return _classDef;
226233
}
@@ -629,7 +636,7 @@ protected void _addCreators(Map<String, POJOPropertyBuilder> props)
629636
}
630637
}
631638
}
632-
if (_classDef.getType().isRecordType()) {
639+
if (isRecordType()) {
633640
List<String> recordComponentNames = new ArrayList<String>();
634641
AnnotatedConstructor canonicalCtor = JDK14Util.findRecordConstructor(
635642
_classDef, _annotationIntrospector, _config, recordComponentNames);
@@ -947,9 +954,9 @@ protected void _removeUnwantedProperties(Map<String, POJOPropertyBuilder> props)
947954
}
948955
// Otherwise, check ignorals
949956
if (prop.anyIgnorals()) {
950-
// Special handling for Records, as they do not have mutators so relying on constructors with (mostly)
951-
// implicitly-named parameters...
952-
if (_classDef.getType().isRecordType()) {
957+
// Special handling for Records, as they do not have mutators so relying on constructors
958+
// with (mostly) implicitly-named parameters...
959+
if (isRecordType()) {
953960
// ...so can only remove ignored field and/or accessors, not constructor parameters that are needed
954961
// for instantiation...
955962
prop.removeIgnored();

0 commit comments

Comments
 (0)