FasterXML / FasterXML/jackson-dataformats-binary
Ion Polymorphic deserialization in 2.12 breaks wrt use of Native Type Ids when upgrading from 2.8
- Dominant language
- Java
- Stars
- 347
- Forks
- 156
- Avg merge
- 3d 3h
- Merged PRs (30d)
- 22
Description
Given the following classes:
```
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.PROPERTY,
property = "base",
visible = true
)
@JsonSubTypes({
@Type(value = Subclass.class, name = "subclass"),
})
static public class BaseClass {
}
public static class Subclass extends BaseClass {
public String base;
}
public static class Container {
public BaseClass objectWithType;
}
```
The following ion can be deserialized using Jackson-dataformat-ion 2.8:
```
{
objectWithType:type::{
base: "subclass"
name: "Some name"
}
}
```
### Current Behavior
When using Jackson-dataformat-ion 2.12.x, the following exception is thrown:
```
com.fasterxml.jackson.databind.exc.InvalidTypeIdException:
Could not resolve type id 'type' as a subtype of `com.fasterxml.jackson.dataformat.ion.polymorphism.PolymorphicTypeAnnotationsTest$BaseClass`: known type ids = [PolymorphicTypeAnnotationsTest$BaseClass, subtype] (for POJO property 'objectWithType')
```
This happens because [IonParser.canReadTypeId()](https://github.com/FasterXML/jackson-dataformats-binary/blob/master/ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonParser.java#L156) always returns true, it makes [Jackson-databind](https://github.com/FasterXML/jackson-databind/blob/df8d7a15a0c0d94a57c35ac31aacef5ed10de58a/src/main/java/com/fasterxml/jackson/databind/jsontype/impl/AsPropertyTypeDeserializer.java#L68) incorrectly read the [field name token](https://amzn.github.io/ion-docs/docs/spec.html#struct) `type::` as a *native type id*.
### Expected Behavior
There should not be an exception. This could be accomplished by allowing the check for *native type ids* to be disabled in the `IonParser` while deserializing, similar to what was added in the `IonGenerator` in #232 during serialization.
Then, the IonMapper could be configured with the following:
```
IonObjectMapper ionMapper = new IonValueMapper();
ionMapper.disable(IonParser.Feature.USE_NATIVE_TYPE_ID)
```
**Note**: disabling **`IonGenerator`**`.Feature.USE_NATIVE_TYPE_ID` (which is already available) doesn't do the trick here.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.