0

I have this code:

ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
objectMapper.registerModule(new MrBeanModule());

and this testcase:

SearchResultContainer src = objectMapper.readValue("{}", SearchResultContainer.class);

SearchResultContainer is a POJO interface (that's the whole reason MRBean is used here).

Why does this fail with the following exception?

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `com.ctc.rets.dto.search.SearchResultContainer` (no Creators, like default construct, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information
 at [Source: (String)"{}"; line: 1, column: 1]
    at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:67)
    at com.fasterxml.jackson.databind.DeserializationContext.reportBadDefinition(DeserializationContext.java:1451)
    at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1027)
    at com.fasterxml.jackson.databind.deser.AbstractDeserializer.deserialize(AbstractDeserializer.java:265)
    at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4001)
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2992)
    at com.ctc.web.client.CustomRestTemplateTest.test1(CustomRestTemplateTest.java:25)
Alex R
  • 11,364
  • 15
  • 100
  • 180
  • Which version of `Jackson` do you use? I checked it with version `2.9.8` and it works properly. – Michał Ziober Apr 25 '19 at 19:48
  • Right on! I had an old version in the path. 2.4.0 with 2.9.5 version of jackson. Updated everything to 2.9.8 and now it works fine. – Alex R Apr 26 '19 at 04:28

1 Answers1

0

Incorrect version of MRBean found in pom.xml.

Fix:

<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.module/jackson-module-mrbean -->
<dependency>
    <groupId>com.fasterxml.jackson.module</groupId>
    <artifactId>jackson-module-mrbean</artifactId>
    <version>2.9.8</version>
</dependency>
Alex R
  • 11,364
  • 15
  • 100
  • 180