2016-12-19 12 views
1

:私はいくつかのデータをsetted名前の変更要素名

public class GenericListInfoResponse<T> extends GenericResponse { 

    private T resultInfo; 

    public GenericListInfoResponse(T resultInfo) { 
     super(); 
     this.resultInfo = resultInfo; 
    } 

    public T getResultInfo() { 
     return resultInfo; 
    } 

    public void setResultInfo(T resultInfo) { 
     this.resultInfo = resultInfo; 
    } 

} 

が私のサービスから来ている:それそれの後

TitleListInfo titleListInfo = dropdownDataService.getTitleList(transactionId); 
response.setResultInfo(titleListInfo); 

この種のJSONを返す:

{ 
    "resultInfo": { 
    "combinedMessage": "", 
    "messageCode": null 
    ... 
} 

「resultInfo」の代わりに要素名の名前を変更したいとします。たとえば "titleInfo"

答えて

0

変数の名前を変更するだけで、それをしたいと思っていますか? @JsonProperty("titleInfo")というフィールドに注釈を付けるとうまくいくはずです。

@JsonProperty("titleInfo") 
private T resultInfo; 

動作しない場合は、代わりにゲッターとセッターに注釈を付けてください。

+0

答えていただきありがとうございますが、動的@JsonPropertyの名前が必要です。私はこのクラスを別のpackegeに再利用します。そして、私はそれをuserInfo、別の場所、おそらくmeberInfoなどの名前に変更したいと思っています。 –

+1

ああ、申し訳ありませんが、これは私がこれを読んで今あなたが望んでいたものです。その時それを見てください:http://stackoverflow.com/questions/22321155/jackson-generics-with-variable-jsonproperty-usage-with-generics – Shadov

+0

@Whatszそれは正解ありがとうございます。私は、私の質問を公表されたものにフラグを立てる。 –

関連する問題