找不到反序列化的非混凝土集合类型 [英] Can not find deserialize for non-concrete Collection type

查看:687
本文介绍了找不到反序列化的非混凝土集合类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是杰克逊库映射到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 列表<解决了这个问题/ code>:

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

private ForeignCollection<MyObject> myObjects;

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

这篇关于找不到反序列化的非混凝土集合类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆