gpt4 book ai didi

rest - JsonMappingException : Already had POJO for id

转载 作者:行者123 更新时间:2023-12-03 13:53:43 29 4
gpt4 key购买 nike

尝试使用 @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 注释上,因为如果我删除注释,问题就会消失(正如我为帐户所做的那样),但据我所知,新功能对循环依赖很有用,这对我在其他情况下很有用。这两个图像之间不应该有冲突,因为它们是不同的对象。
我该如何解决这个问题或者是什么问题?

最佳答案

您应该使用 scope注释 id 时的参数。然后反序列化器将确保 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)

关于rest - JsonMappingException : Already had POJO for id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15422838/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com