我的控制器无法映射 Google GuavaMultimap
来自前端。我从我的 Javascript 发送这个对象:
{1:[true,false], 2:[false,true], ...}.
如果我使用一个标准
java.util.Map<Long, List<Boolean>>
一切正常。但番石榴则不然Multimap
。我是否必须配置 Spring 才能使用某些自定义转换器,或者有什么问题?
控制器是:
@RequestMapping(path = "/myurl", method = RequestMethod.POST, produces = CotrollerKonstanten.JSON_UTF8)
public long myMethod(@RequestBody MappingDto mappingDto) {
//...
}
我的例外是:
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
Did you 注册 Guava 模块 https://github.com/FasterXML/jackson-datatypes-collections/tree/master/guava?默认情况下,Jackson(以及 Spring)不支持序列化或反序列化为 Guava 数据类型。
Guava 模块可能适合你,也可能不适合你,这取决于它的实现Multimap
你想要的——并非所有数据类型都被实现。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)