Ewg*_*ski 1 mapping spring-mvc multimap guava
我的控制器无法映射Multimap来自前端的 Google Guava 。我从我的 Javascript 发送这个对象:
{1:[true,false], 2:[false,true], ...}.
Run Code Online (Sandbox Code Playgroud)
如果我使用标准
java.util.Map<Long, List<Boolean>>
Run Code Online (Sandbox Code Playgroud)
一切正常。但不能用番石榴Multimap。我是否必须配置 Spring 才能使用某些自定义转换器,或者有什么问题?
控制器是:
@RequestMapping(path = "/myurl", method = RequestMethod.POST, produces = CotrollerKonstanten.JSON_UTF8)
public long myMethod(@RequestBody MappingDto mappingDto) {
//...
}
Run Code Online (Sandbox Code Playgroud)
我的例外是:
Run Code Online (Sandbox Code Playgroud)org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Can not construct instance of com.google.common.collect.Multimap, problem: abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information at [Source: java.io.PushbackInputStream@4b9c2db; line: 1, column: 13] (through reference chain: ...myClass); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of com.google.common.collect.Multimap, problem: abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information
您是否注册了 Guava 模块?默认情况下,Jackson(以及 Spring)不支持序列化或反序列化到 Guava 数据类型。
Guava 模块可能适合您,也可能不适合您,具体取决于Multimap您想要的实现方式——并非所有数据类型都已实现。
| 归档时间: |
|
| 查看次数: |
820 次 |
| 最近记录: |