我正在使用 Jackson 将 POJO 转换为 JSON 以存储在数据库中。但是我有一个我想忽略的 setter/getter 。我看到了很多与@JsonIgnoreProperties 相关的信息,但我似乎无法取得任何进展。我基本上想要@Transient 的等价物。
基本用例(我想忽略 InternationalNumber):
public class PhoneNumber {
private String country;
private String number;
public PhoneNumber() {}
public String getCountry() {
return country;
}
public String getLocalNumber() {
return localNumber;
}
public String getInternationalNumber() {
String result = "Not Available";
if (country != null && localNumber != null) {
result = new PhoneNumberHandler().internationalFormat(
localNumber, WorldCountries.countryToIso2Code(country));
}
return result;
}
}
最佳答案
那就是 @JsonIgnore
关于 getter 方法。
https://stackoverflow.com/questions/13533629/
相关文章:
asp.net-mvc - 如何从 MVC Controller 返回 Json 对象以查看
jquery - AJAX 将 JavaScript 字符串数组发布到 JsonResult 作为
java - 可以将 Jackson 配置为从所有字符串属性中修剪前导/尾随空格吗?
javascript - 如何转换为 D3 的 JSON 格式?
php - 使用 json_encode() 时删除数组索引引用
json - 在 node package.json 中,使用额外参数从另一个脚本调用脚本,在这种情