-
Notifications
You must be signed in to change notification settings - Fork 101
Description
Describe the bug
Type-level @JsonbTypeDeserializer and @JsonbTypeSerializer annotations are not being recognized when the annotated types are used as elements or values in container types (Maps, Collections, Arrays, Optionals).
Affected Containers:
- Map values:
Map<String, AnnotatedType> - Collection elements:
List<AnnotatedType>,Set<AnnotatedType>, etc. - Array elements:
AnnotatedType[] - Optional values:
Optional<AnnotatedType>
To Reproduce
@JsonbTypeDeserializer(AInterfaceCustomDeserializer.class)
public interface AInterface {
}public static class AInterfaceCustomDeserializer implements JsonbDeserializer<AInterface> {
@Override
public AInterface deserialize(JsonParser parser, DeserializationContext ctx, Type type) {
// Custom deserialization logic
return new AClass();
}
}public static class Container {
private AInterface aInterface; // Works - custom deserializer is invoked
private Map<String, AInterface> map; // Fails - custom deserializer is NOT invoked
}When deserializing JSON into the Container class, the direct aInterface property works correctly, but the map values fail because the custom deserializer is not recognized. The same is true when attempting to serialize.
Expected behavior
When a type is annotated with @JsonbTypeDeserializer, the custom deserializer should be invoked regardless of whether the type is used as:
- A direct property type
- An element in a collection
- A value in a map
- An element in an array
- A wrapped value in an Optional
Actual Behavior
The custom deserializer is only invoked when the annotated type is used directly as a property type. When used as a container element/value, deserialization fails with an error like:
Cannot infer a type for unmarshalling into:
This occurs because the type-level @JsonbTypeDeserializer annotation is not being detected.
System information:
- OS: Linuc
- Java Version: 21
- Yasson Version: 3.0.4