找不到反序列化的非混凝土集合类型找不到、混凝土、类型、序列化

由网友(凉夜ˋ已成梦)分享简介:我使用的是杰克逊库映射到JSON对象。我已经简化问题的很多的,这是发生了什么:I'm using the jackson library to map JSON into objects. I've simplified the problem a lot, this is what happens:public...

我使用的是杰克逊库映射到JSON对象。我已经简化问题的很多的,这是发生了什么:

I'm using the jackson library to map JSON into objects. I've simplified the problem a lot, this is what happens:

public class MyObject{

    public ForeignCollection<MySecondObject> getA(){
        return null;
    }

    public ForeignCollection<MyThirdObject> getB(){
        return null;
    }
}

我解析了一个空JSON字符串:

I'm parsing the an empty JSON string:

ObjectMapper mapper = new ObjectMapper();
mapper.readValue("{}", MyObject.class);

readValue ,我得到这个异​​常:

On readValue, I get this Exception:

com.fasterxml.jackson.databind.JsonMappingException: Can not find a deserializer for non-concrete Collection type [collection type; class com.j256.ormlite.dao.ForeignCollection, contains [simple type, class com.test.MyThirdObject]]

这发生在我的两个的 GET 为MyObject 类方法,它们的回报一个 ForeignCollection 。除去在没有例外的 GET 方法的结果之一。

This happens when I have two get methods in the MyObject class which return a ForeignCollection. Removing one of the get methods results in no exceptions.

我实际上由映射器着眼于 GET 方法的事实感到惊讶,它应该只是设置我指示等领域。

I'm actually surprised by the fact that the mapper looks at the get methods, it should just set the fields I indicate.

这是怎么回事?

推荐答案

我通过把 ForeignCollection 列表:

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

private ForeignCollection<MyObject> myObjects;

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