如何在一个字段取决于另一字段的值时有条件地反序列化

时间:2019-05-17 07:12:13

标签: java jackson jsonparser

我的json可以是以下两种类型

{
 "corresponding_address_same_as_permanent_address": "yes",
 "corresponding_address" : "123,abc",
 "corresponding_pincode" : "484333"
}

{
 "corresponding_address_same_as_permanent_address": "no",
 "corresponding_address" : "123,abc",
 "corresponding_pincode" : "484333",
 "permanent_address" : "123,perm",
 "permanent_pincode" : "484332"
}

我有一个Java类:

class Address {
  String corresponding_address_same_as_permanent_address;
  String corresponding_address;
  String corresponding_pincode;
  String permanent_address;
  String permanent_pincode;
}

取决于字段corresponding_address_same_as_permanent_address 我需要在代码中设置字段permanent_addresspermanent_pincode。在这种情况下,哪些注释会有所帮助?

0 个答案:

没有答案