Jackson JSON 处理器在反序列化期间覆盖对象的属性
我有一个有趣的问题。 Jackson 用具有相同名称的“子”对象的属性值覆盖“父”对象的属性值。因此,更准确地说,这是我拥有的 Java 结构。
public class Contact {
...
String name;
List<Email> emails;
List<PhoneNumbers> phoneNumbers;
Account account;
...
}
public class Account {
...
String accountName;
List<Email> emails;
List<PhoneNumbers> phoneNumbers;
Account account;
...
}
因此,当我形成 Contact JSON 对象并将其发送到服务器时,一切都会正常,直到 BeanDeserializer 考虑 Contact 类的属性。然后,它开始读取 JSON 的帐户部分的属性,这是可以的,但不会创建帐户实例来将其设置为联系人 - 它将帐户属性的值写入与联系人实例名称相同的属性中。
我很困惑,不知道从哪里开始寻找如何解决这个问题。
I have interesting problem. Jackson overwrites values of properties on the 'parent' object with values of properties of 'child' object that have same name. So, to be more precise, this is Java structure I have
public class Contact {
...
String name;
List<Email> emails;
List<PhoneNumbers> phoneNumbers;
Account account;
...
}
public class Account {
...
String accountName;
List<Email> emails;
List<PhoneNumbers> phoneNumbers;
Account account;
...
}
So, when I form Contact JSON object and send it to server, everything goes fine until BeanDeserializer comes into account property of Contact class. Then, it starts reading proeprties of account part of JSON, which is ok, but does not create Account instance to set it on contact - it writes values of account's properties into properties with same names of Contact instance.
I am confused and not sure where to start looking how to fix this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我无法重现与原始问题中描述的类似的任何问题。
以下示例是根据原始问题中的描述创建的,按预期工作,没有错误或不正确的反序列化。
I'm not able to reproduce any problem similar to what's described in the original question.
The following example, created based on the descriptions in the original question, works as expected, without errors or improper deserialization.