この豆State
:
public class State {
private boolean isSet;
@JsonProperty("isSet")
public boolean isSet() {
return isSet;
}
@JsonProperty("isSet")
public void setSet(boolean isSet) {
this.isSet = isSet;
}
}
ajax コールバックを使用してネットワーク経由で送信されますsuccess
:
success : function(response) {
if(response.State.isSet){
alert('success called successfully)
}
}
ここで注釈は@JsonProperty
必要ですか? それを使用する利点は何ですか? 副作用を引き起こすことなくこの注釈を削除できると思います。
これについて読むジャクソン注釈これをいつ使用する必要があるのか分かりません。
ベストアンサー1
.Net
ここに良い例があります。JSON はプロパティが大文字で始まる環境から来ているので、変数の名前を変更するために使用します。
public class Parameter {
@JsonProperty("Name")
public String name;
@JsonProperty("Value")
public String value;
}
これは JSON との間で正しく解析されます:
"Parameter":{
"Name":"Parameter-Name",
"Value":"Parameter-Value"
}