Spring MVC映射Guava Multimap [英] Spring MVC mapping Guava Multimap
问题描述
我的控制器无法映射来自前端的Google Guava Multimap
.我从Javascript发送了这个对象:
My controller can't map a Google Guava Multimap
coming from the frontend. I send from my Javascript this object:
{1:[true,false], 2:[false,true], ...}.
如果我使用标准
java.util.Map<Long, List<Boolean>>
一切正常.但番石榴Multimap
则不行.我是否必须配置Spring以使用某些自定义转换器,还是有什么问题?
everything works fine. But not with the Guava Multimap
. Do I have to configure Spring to use some custom converter, or what is the problem?
控制器为:
@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 register the Guava module? By default, Jackson (and hence Spring) does not support serializing or deserializing to Guava datatypes.
Guava模块可能对您有用,也可能不起作用,这取决于您想要实现Multimap
的方式-并非所有数据类型都得到实现.
The Guava module may or may not work for you depending on what implementation of Multimap
you want -- not all datatypes are implemented.
这篇关于Spring MVC映射Guava Multimap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!