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

Abstract Type mapping in 2.9 fails when multiple modules are registered #2019

Closed
asger82 opened this issue May 1, 2018 · 2 comments
Closed
Milestone

Comments

@asger82
Copy link

asger82 commented May 1, 2018

If multiple modules are used to map abstract types, deserialization might fail in 2.9+:

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of model.Datatype1 (no Creators, like default construct, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information

The bug can be reproduced for version 2.9+ in the attached maven project.

I guess the bug was introduced due to a modification of _mapAbstractType2 in com.fasterxml.jackson.databind.deser.BasicDeserializerFactory:

2.9:
JavaType concrete = resolver.findTypeMapping(config, type);
if (ClassUtil.rawClass(concrete) != currClass) {
return concrete;
}

2.8
if (concrete != null && concrete.getRawClass() != currClass) {
return concrete;
}

The not null check is needed for continuing iterating other modules for abstract type mappings.

jackson-error-example.zip

Best regards
Asger Christiansen

@cowtowncoder
Copy link
Member

Thank you for reporting this, providing reproduction. Sounds like bug indeed.

@cowtowncoder cowtowncoder added this to the 2.9.6 milestone May 2, 2018
cowtowncoder added a commit that referenced this issue May 2, 2018
@erdemedeiros
Copy link

I'm using this workaround while waiting for 2.9.6:

        SimpleAbstractTypeResolver resolver = new SimpleAbstractTypeResolver(){
            @Override
            public JavaType resolveAbstractType(DeserializationConfig config,
                                                BeanDescription typeDesc) {
                return findTypeMapping(config, typeDesc.getType());
            }
        };
        resolver.addMapping(MyInterface.class,
                            MyImplementation.class);

        module.setAbstractTypes(resolver);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants