Can not find deserialize for non-concrete Collection type

喜欢而已 提交于 2019-11-29 16:40:13

You need to use the Guava module in your ObjectMapper. Here is the Maven dependency:

<dependency>
  <groupId>com.fasterxml.jackson.datatype</groupId>
  <artifactId>jackson-datatype-guava</artifactId>
  <version>{whatever is the latest}</version>
</dependency>

In your code:

ObjectMapper mapper = new ObjectMapper();
// register module with object mapper
mapper.registerModule(new GuavaModule());

You can omit the @JsonDeserialize and @JsonSerialize annotations.

More info here.

I've fixed this by converting the ForeignCollection to a List:

private ForeignCollection<MyObject> myObjects;

public List<MyObject> getMyObjects(){
    return new ArrayList<MyObject>(myObjects);
}

You may need to define custom deserializer for ForeignCollection; or, if there is known implementation class, use annotation:

@JsonDeserialize(as=ForeignCollectionImpl.class)

to indicate which concrete sub-class to use for that abstract type.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!