1

My problem is like "Jackson and generic type reference", but with the added wrinkle that my generic class is abstract, so I have to map it to a concrete type. this used to work fine under Jackson v2.5.3, but recent changes in Jackson (v2.7.2 or earlier) have broken it.

I have abstract class Page and concrete class PageImpl. I used to be able to deserialize Page as PageImpl, no problem:

SimpleModule module = new SimpleModule().addAbstractTypeMapping(Page.class, PageImpl.class)
ObjectMapper objectMapper = new ObjectMapper().registerModule(module);

but now, I've learned via debugging the source, that when Jackson maps an abstract type to a concrete type, it drops type bindings. that means that if I tell Jackson to deser a given JSON string into type Page< XYZ >...

value = objectMapper.readValue(json,
    typeFactory.constructSimpleType(Page.class,
        new JavaType[]{typeFactory.constructSimpleType(XYZ.class, null)}));

...that it'll map the output type to PageImpl, but it drops the type bindings before deserializing the JSON into PageImpl. this results in the PageImpl POJO containing a List of LinkedHashMap objects, instead of a list of XYZ objects.

I'm not sure why Jackson was changed like this; it seems like a bug. Looking for suggestions on a workaround. thanks!

Community
  • 1
  • 1
ur-vogel
  • 364
  • 1
  • 2
  • 11

1 Answers1

1

Try 2.7.5: there were some issues due to type resolution rewrite, and while most were fixed by 2.7.3, there was one more in 2.7.4. So in all likelihood you did indeed hit a bug.

In general it is good idea to try out the latest patch version of the minor version you have: there is no good reason to use 2.7.2 at this point, over 2.7.5.

StaxMan
  • 102,903
  • 28
  • 190
  • 229