我正在尝试反序列化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)
我得到一个例外:
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]
有趣的是,如果我使用String保持响应值并使用注入的ObjectMapper,我可以反序列化响应我该怎么办?
如果需要自定义(例如添加其他消息转换器),请使用RestTemplateBuilder @Bean。
我假设RestTemplateBuilder使用相同的RestTemplate,因此,如果为RestTemplate注册了一个模块,则应该为RestTemplateBuilder注册一个模块