1

I'm trying to deserialize Jackson Multimap

       //given
        val newUser = NewUserDTO(ALREADY_TAKEN_USERNAME, ALREADY_TAKEN_EMAIL,"qddqwdW221QZ&^$!")

        //when
        val response = restTemplate.exchange("http://localhost:${port}/user", HttpMethod.POST, HttpEntity(newUser), typeReference())

        //then
        Assertions.assertEquals(HttpStatus.UNPROCESSABLE_ENTITY, response.statusCode)

I get an exception:

Type definition error: [simple type, class io.vavr.collection.Multimap]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `io.vavr.collection.Multimap` (no Creators, like default constructor, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information
 at [Source: (PushbackInputStream); line: 1, column: 1]
org.springframework.http.converter.HttpMessageConversionException: Type definition error: [simple type, class io.vavr.collection.Multimap]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `io.vavr.collection.Multimap` (no Creators, like default constructor, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information
 at [Source: (PushbackInputStream); line: 1, column: 1]

Interestingly i can deserialize response if I use String for holding it value and use injected ObjectMapper What should i do?

  • Check If jackson is using this mentioned instance of ObjectMapper. – Benjamin Eckardt Jun 02 '20 at 21:40
  • @BenjaminEckardt yes, i contains both VavrModule and KotlinModule - check it by debugging AbstractJackson2HttpMessageConverter. Moreover, RestController returns correctly serialized Multimap – Aleksander Ściborek Jun 02 '20 at 22:04
  • Hi @AleksanderŚciborek, did your problem resolve? Could you share your class containing the VAVR Multimap? Feel free to create an issue on https://github.com/vavr-io/vavr-jackson/issues if you think there is a bug – Mincong Huang Jun 05 '20 at 20:28
  • @MincongHuang i wasn't able to handle with that issue directly. I've used callback references(RequestCallback and ResponseExtractor) - those both have worked ;) – Aleksander Ściborek Jun 05 '20 at 22:12

1 Answers1

0

Ok, that was my fault. I've used TestRestTemplate, and like documentation describe it, i should configure that bean by myself:

If you need customizations (for example to adding additional message converters) use a RestTemplateBuilder @Bean.

I assumed that RestTemplateBuilder uses the same RestTemplate, therefore if a module is registered for RestTemplate, it should be registered for RestTemplateBuilder