I want to convert java object to JSON with different object name. For Example :
public class MetaProfileResponse {
private Boolean tour ;
private Integer maxFreeUser;
private Boolean paid;
private Integer status;
}
other Class is :
public class ProfileResponse {
private String domainName;
private String companyName;
private String country;
private String postCode;
}
A class have object of both class :
public class GetProfileResponse {
private MetaProfileResponse metaProfileResponse;
private ProfileResponse profileResponse;
}
when we get response as JSON We got :
{"metaProfileResponse":{"tour":null,"maxFreeUser":25,"paid":false,"status":0},"profileResponse":{"domainName":null,"companyName":null,"country":null,"postCode":null}}
But We want result as : {"meta":{"tour":null,"maxFreeUser":25,"paid":false,"status":0},"profile":{"domainName":null,"companyName":null,"country":null,"postCode":null}}
without changing class name
You can use the annotation @JsonProperty(value="whateverValueYouWant")
on the getter of metaProfileResponse;
It should give you proper result.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.