Skip to content

Fixed #5094: add lazy construction of BeanDescription for deserialization #5096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Versions: 3.x (for earlier see VERSION-2.x)

#5093: Change the way `BeanDescription` passed during serializer construction
to use `Supplier`
#5094: Change the way `BeanDescription` passed during deserializer construction
to use `Supplier`

3.0.0-rc3 (13-Apr-2025)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public JavaType findTypeMapping(DeserializationConfig config, JavaType type) {
* including defaulting.
*
* @param config Configuration in use
* @param typeDesc Description of the POJO type to resolve
* @param typeDescRef Description of the POJO type to resolve
*
* @return Resolved concrete type (which should retain generic
* type parameters of input type, if any), if resolution succeeds;
* null if resolver does not know how to resolve given type
*/
public JavaType resolveAbstractType(DeserializationConfig config,
BeanDescription typeDesc) {
BeanDescription.Supplier typeDescRef) {
return null;
}
}
4 changes: 4 additions & 0 deletions src/main/java/tools/jackson/databind/BeanDescription.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ public AnnotatedClass getClassInfo() {
return get().getClassInfo();
}

public Annotations getClassAnnotations() {
return get().getClassAnnotations();
}

@Override
public BeanDescription get() {
if (_beanDesc == null) {
Expand Down
28 changes: 27 additions & 1 deletion src/main/java/tools/jackson/databind/DeserializationContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -536,12 +536,31 @@ public BeanDescription introspectBeanDescriptionForCreation(JavaType type) {
return classIntrospector().introspectForCreation(type);
}

public BeanDescription.Supplier lazyIntrospectBeanDescriptionForCreation(JavaType type) {
return new BeanDescription.Supplier(type) {
@Override
public BeanDescription _construct(JavaType forType) {
return introspectBeanDescriptionForCreation(forType);
}
};
}

public BeanDescription introspectBeanDescriptionForBuilder(JavaType builderType,
BeanDescription valueTypeDesc) {
return classIntrospector().introspectForDeserializationWithBuilder(builderType,
valueTypeDesc);
}

public BeanDescription.Supplier lazyIntrospectBeanDescriptionForBuilder(final JavaType builderType,
final BeanDescription valueTypeDesc) {
return new BeanDescription.Supplier(builderType) {
@Override
public BeanDescription _construct(JavaType forType) {
return introspectBeanDescriptionForBuilder(forType, valueTypeDesc);
}
};
}

/*
/**********************************************************************
/* Misc config access
Expand Down Expand Up @@ -1890,8 +1909,15 @@ public <T> T reportBadTypeDefinition(BeanDescription bean,
* regarding specific property (of a type), unrelated to actual JSON content to map.
* Default behavior is to construct and throw a {@link DatabindException}.
*/
public <T> T reportBadPropertyDefinition(BeanDescription.Supplier beanDescRef,
BeanPropertyDefinition prop, String msg, Object... msgArgs)
throws DatabindException
{
return reportBadPropertyDefinition(beanDescRef.get(), prop, msg, msgArgs);
}

public <T> T reportBadPropertyDefinition(BeanDescription bean, BeanPropertyDefinition prop,
String msg, Object... msgArgs)
String msg, Object... msgArgs)
throws DatabindException
{
msg = _format(msg, msgArgs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ public class AbstractDeserializer
* to bind)
*/
public AbstractDeserializer(BeanDeserializerBuilder builder,
BeanDescription beanDesc, Map<String, SettableBeanProperty> backRefProps,
Map<String, SettableBeanProperty> backRefProps,
Map<String, SettableBeanProperty> props)
{
_baseType = beanDesc.getType();
_baseType = builder.getType();
_objectIdReader = builder.getObjectIdReader();
_backRefProperties = backRefProps;
_properties = props;
Expand All @@ -66,9 +66,9 @@ public AbstractDeserializer(BeanDeserializerBuilder builder,
_acceptDouble = (cls == Double.TYPE) || cls.isAssignableFrom(Double.class);
}

protected AbstractDeserializer(BeanDescription beanDesc)
protected AbstractDeserializer(JavaType baseType)
{
_baseType = beanDesc.getType();
_baseType = baseType;
_objectIdReader = null;
_backRefProperties = null;
Class<?> cls = _baseType.getRawClass();
Expand Down Expand Up @@ -96,8 +96,8 @@ protected AbstractDeserializer(AbstractDeserializer base,
* Factory method used when constructing instances for non-POJO types, like
* {@link java.util.Map}s.
*/
public static AbstractDeserializer constructForNonPOJO(BeanDescription beanDesc) {
return new AbstractDeserializer(beanDesc);
public static AbstractDeserializer constructForNonPOJO(BeanDescription.Supplier beanDescRef) {
return new AbstractDeserializer(beanDescRef.getType());
}

@Override
Expand Down
Loading