Spring 使用RestTemplae获取vavr Multimap后出现反序列化错误

Spring 使用RestTemplae获取vavr Multimap后出现反序列化错误,spring,kotlin,resttemplate,vavr,Spring,Kotlin,Resttemplate,Vavr,我正在尝试反序列化Jackson Multimap //given val newUser = NewUserDTO(ALREADY_TAKEN_USERNAME, ALREADY_TAKEN_EMAIL,"qddqwdW221QZ&^$!") //when val response = restTemplate.exchange("http://localhost:${port}/user", HttpMethod.POS

我正在尝试反序列化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]
有趣的是,若我使用字符串保存响应值并使用注入的ObjectMapper,那个么我可以反序列化响应
我该怎么办?好吧,那是我的错。我使用了TestRestTemplate,就像文档描述的那样,我应该自己配置这个bean:

如果您需要定制(例如添加额外的消息转换器),请使用restemplatebuilder@Bean


我假设RestTemplateBuilder使用相同的RestTemplate,因此,如果模块注册为RestTemplate,那么它应该注册为RestTemplateBuilder,这是我的错。我使用了TestRestTemplate,就像文档描述的那样,我应该自己配置这个bean:

如果您需要定制(例如添加额外的消息转换器),请使用restemplatebuilder@Bean


我假设RestTemplateBuilder使用相同的RestTemplate,因此如果模块注册为RestTemplate,则应注册为RestTemplateBuilder

检查jackson是否正在使用上述ObjectMapper实例。@BenjamineCardt是,我同时包含VavrModule和KotlinModule-通过调试AbstractJackson2HttpMessageConverter来检查它。此外,RestController返回正确序列化的MultimapHi@AleksanderŚciborek,您的问题解决了吗?你能分享你的包含VAVR多重地图的课程吗?如果您认为存在问题,请随时在上创建问题bug@MincongHuang我无法直接处理那个问题。我使用过回调引用(RequestCallback和ResponseExtractor)——它们都有效;)检查jackson是否正在使用上述ObjectMapper实例。@BenjaminEckardt是的,我同时包含VavrModule和KotlinModule-通过调试AbstractJackson2HttpMessageConverter来检查。此外,RestController返回正确序列化的MultimapHi@AleksanderŚciborek,您的问题解决了吗?你能分享你的包含VAVR多重地图的课程吗?如果您认为存在问题,请随时在上创建问题bug@MincongHuang我无法直接处理那个问题。我使用过回调引用(RequestCallback和ResponseExtractor)——它们都有效;)