簡體   English   中英

將Java對象轉換為具有不同對象名稱的json

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM