[英]How to convert json string to java object, if json property name and java object property are different
[英]convert java object to json with different object name
我想将Java对象转换为具有不同对象名称的JSON。 例如 :
public class MetaProfileResponse {
private Boolean tour ;
private Integer maxFreeUser;
private Boolean paid;
private Integer status;
}
其他类是:
public class ProfileResponse {
private String domainName;
private String companyName;
private String country;
private String postCode;
}
一个类具有两个类的对象:
public class GetProfileResponse {
private MetaProfileResponse metaProfileResponse;
private ProfileResponse profileResponse;
}
当我们以JSON格式获得响应时,我们得到:
{“ metaProfileResponse”:{“ tour”:null,“ maxFreeUser”:25,“ paid”:false,“ status”:0},“ profileResponse”:{“ domainName”:null,“ companyName”:null,“ country “:null,” postCode“:null}}
但是我们希望结果为:{“元”:{“游览”:null,“ maxFreeUser”:25,“付费”:false,“状态”:0},“配置文件”:{“域名”:null,“ companyName “:null,” country“:null,” postCode“:null}}
无需更改班级名称
您可以在@JsonProperty(value="whateverValueYouWant")
方法上使用注释@JsonProperty(value="whateverValueYouWant")
metaProfileResponse;
它应该给您适当的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.