Skip to content
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

Ion Polymorphic deserialization in 2.12 breaks wrt use of Native Type Ids when upgrading from 2.8 #270

Open
manaigrn-amzn opened this issue Apr 1, 2021 · 1 comment
Labels
Milestone

Comments

@manaigrn-amzn
Copy link
Contributor

manaigrn-amzn commented Apr 1, 2021

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() always returns true, it makes Jackson-databind incorrectly read the field name token 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.

manaigrn-amzn added a commit to manaigrn-amzn/jackson-dataformats-binary that referenced this issue Apr 1, 2021
manaigrn-amzn added a commit to manaigrn-amzn/jackson-dataformats-binary that referenced this issue Apr 1, 2021
manaigrn-amzn added a commit to manaigrn-amzn/jackson-dataformats-binary that referenced this issue Apr 1, 2021
manaigrn-amzn added a commit to manaigrn-amzn/jackson-dataformats-binary that referenced this issue Apr 1, 2021
manaigrn-amzn added a commit to manaigrn-amzn/jackson-dataformats-binary that referenced this issue Apr 1, 2021
@cowtowncoder cowtowncoder modified the milestones: 2.10.0, 2.12.3 Apr 6, 2021
@cowtowncoder
Copy link
Member

Solved by addition of:

IonParser.Feature.USE_NATIVE_TYPE_ID

@cowtowncoder cowtowncoder changed the title [Jackson-dataformat-ion - 2.12x] Polymorphic deserialization breaks when upgrading from 2.8 Ion Polymorphic deserialization in 2.12 breaks wrt use of Native Type Ids when upgrading from 2.8 Apr 6, 2021
cowtowncoder added a commit that referenced this issue Apr 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants