休息 – JsonMappingException:已经有POJO for id

前端之家收集整理的这篇文章主要介绍了休息 – JsonMappingException:已经有POJO for id前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
尝试使用@JsonIdentityInfo jackson注释时出现错误.当我尝试反序列化对象时,我会得到以下的例外:

Could not read JSON: Already had POJO for id (java.lang.Integer) [1] (through reference chain: eu.cobiz.web.domain.Site[“operators”]->eu.yavix.web.domain.Account[“image”]->eu.cobiz.web.domain.Image[“@Image”]);nested exception is com.fasterxml.jackson.databind.JsonMappingException: Already had POJO for id (java.lang.Integer) [1] (through reference chain: eu.yavix.web.domain.Site[“operators”]->eu.cobiz.web.domain.Account[“image”]->eu.cobiz.web.domain.Image[“@Image”])

我试图反序列化的JSON看起来像:

{
"@Site": 1,"siteId": 1,"name": "0","address": {
    "@Address": 2,"addressId": 4,"number": "22"
},"operators": [
    {
        "accountId": 1,"email": "user982701361@yavix.eu","image": {
            "@Image": 1,"imageId": 1,"uri": "http://icons.iconarchive.com/icons/deleket/purple-monsters/128/Alien-awake-icon.png"
        }
    },{
        "accountId": 2,"email": "user174967957@yavix.eu","image": {
            "@Image": 2,"imageId": 2,"uri": "http://icons.iconarchive.com/icons/deleket/purple-monsters/128/Alien-awake-icon.png"
        }
    }
]
}

我的域对象被注释

@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class,property = "@Image")

问题出现在@Id注释,因为如果我删除注释问题消失(就像我做了帐号),但是我的理解是,新功能对于循环依赖是有用的,在其他情况下对我来说是有用的.两个图像之间不应该有冲突,因为它们是不同的对象.

有谁有一个想法如何解决或什么问题?

解决方法

在注释ids时,应该使用scope属性.然后解串器将确保id在范围内是唯一的.

从注释类型JsonIdentityInfo:

Scope is used to define applicability of an Object Id: all ids must be unique within their scope; where scope is defined as combination of this value and generator type.

例如@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class,property =“@ id”,scope = Account.class)

原文链接:https://www.f2er.com/js/155411.html

猜你在找的JavaScript相关文章