Skip to content

Commit a0948db

Browse files
authored
Fixed #5094: add lazy construction of BeanDescription for deserialization (#5096)
1 parent 34966f4 commit a0948db

38 files changed

+442
-388
lines changed

release-notes/VERSION

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Versions: 3.x (for earlier see VERSION-2.x)
99

1010
#5093: Change the way `BeanDescription` passed during serializer construction
1111
to use `Supplier`
12+
#5094: Change the way `BeanDescription` passed during deserializer construction
13+
to use `Supplier`
1214

1315
3.0.0-rc3 (13-Apr-2025)
1416

src/main/java/tools/jackson/databind/AbstractTypeResolver.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ public JavaType findTypeMapping(DeserializationConfig config, JavaType type) {
3939
* including defaulting.
4040
*
4141
* @param config Configuration in use
42-
* @param typeDesc Description of the POJO type to resolve
42+
* @param typeDescRef Description of the POJO type to resolve
4343
*
4444
* @return Resolved concrete type (which should retain generic
4545
* type parameters of input type, if any), if resolution succeeds;
4646
* null if resolver does not know how to resolve given type
4747
*/
4848
public JavaType resolveAbstractType(DeserializationConfig config,
49-
BeanDescription typeDesc) {
49+
BeanDescription.Supplier typeDescRef) {
5050
return null;
5151
}
5252
}

src/main/java/tools/jackson/databind/BeanDescription.java

+4
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,10 @@ public AnnotatedClass getClassInfo() {
323323
return get().getClassInfo();
324324
}
325325

326+
public Annotations getClassAnnotations() {
327+
return get().getClassAnnotations();
328+
}
329+
326330
@Override
327331
public BeanDescription get() {
328332
if (_beanDesc == null) {

src/main/java/tools/jackson/databind/DeserializationContext.java

+27-1
Original file line numberDiff line numberDiff line change
@@ -536,12 +536,31 @@ public BeanDescription introspectBeanDescriptionForCreation(JavaType type) {
536536
return classIntrospector().introspectForCreation(type);
537537
}
538538

539+
public BeanDescription.Supplier lazyIntrospectBeanDescriptionForCreation(JavaType type) {
540+
return new BeanDescription.Supplier(type) {
541+
@Override
542+
public BeanDescription _construct(JavaType forType) {
543+
return introspectBeanDescriptionForCreation(forType);
544+
}
545+
};
546+
}
547+
539548
public BeanDescription introspectBeanDescriptionForBuilder(JavaType builderType,
540549
BeanDescription valueTypeDesc) {
541550
return classIntrospector().introspectForDeserializationWithBuilder(builderType,
542551
valueTypeDesc);
543552
}
544553

554+
public BeanDescription.Supplier lazyIntrospectBeanDescriptionForBuilder(final JavaType builderType,
555+
final BeanDescription valueTypeDesc) {
556+
return new BeanDescription.Supplier(builderType) {
557+
@Override
558+
public BeanDescription _construct(JavaType forType) {
559+
return introspectBeanDescriptionForBuilder(forType, valueTypeDesc);
560+
}
561+
};
562+
}
563+
545564
/*
546565
/**********************************************************************
547566
/* Misc config access
@@ -1890,8 +1909,15 @@ public <T> T reportBadTypeDefinition(BeanDescription bean,
18901909
* regarding specific property (of a type), unrelated to actual JSON content to map.
18911910
* Default behavior is to construct and throw a {@link DatabindException}.
18921911
*/
1912+
public <T> T reportBadPropertyDefinition(BeanDescription.Supplier beanDescRef,
1913+
BeanPropertyDefinition prop, String msg, Object... msgArgs)
1914+
throws DatabindException
1915+
{
1916+
return reportBadPropertyDefinition(beanDescRef.get(), prop, msg, msgArgs);
1917+
}
1918+
18931919
public <T> T reportBadPropertyDefinition(BeanDescription bean, BeanPropertyDefinition prop,
1894-
String msg, Object... msgArgs)
1920+
String msg, Object... msgArgs)
18951921
throws DatabindException
18961922
{
18971923
msg = _format(msg, msgArgs);

src/main/java/tools/jackson/databind/deser/AbstractDeserializer.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ public class AbstractDeserializer
5252
* to bind)
5353
*/
5454
public AbstractDeserializer(BeanDeserializerBuilder builder,
55-
BeanDescription beanDesc, Map<String, SettableBeanProperty> backRefProps,
55+
Map<String, SettableBeanProperty> backRefProps,
5656
Map<String, SettableBeanProperty> props)
5757
{
58-
_baseType = beanDesc.getType();
58+
_baseType = builder.getType();
5959
_objectIdReader = builder.getObjectIdReader();
6060
_backRefProperties = backRefProps;
6161
_properties = props;
@@ -66,9 +66,9 @@ public AbstractDeserializer(BeanDeserializerBuilder builder,
6666
_acceptDouble = (cls == Double.TYPE) || cls.isAssignableFrom(Double.class);
6767
}
6868

69-
protected AbstractDeserializer(BeanDescription beanDesc)
69+
protected AbstractDeserializer(JavaType baseType)
7070
{
71-
_baseType = beanDesc.getType();
71+
_baseType = baseType;
7272
_objectIdReader = null;
7373
_backRefProperties = null;
7474
Class<?> cls = _baseType.getRawClass();
@@ -96,8 +96,8 @@ protected AbstractDeserializer(AbstractDeserializer base,
9696
* Factory method used when constructing instances for non-POJO types, like
9797
* {@link java.util.Map}s.
9898
*/
99-
public static AbstractDeserializer constructForNonPOJO(BeanDescription beanDesc) {
100-
return new AbstractDeserializer(beanDesc);
99+
public static AbstractDeserializer constructForNonPOJO(BeanDescription.Supplier beanDescRef) {
100+
return new AbstractDeserializer(beanDescRef.getType());
101101
}
102102

103103
@Override

0 commit comments

Comments
 (0)