json - Jackson JSON Marshall 忽略 getter

我正在使用 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/

相关文章:

json - 简单、安全的 API 认证系统

asp.net-mvc - 如何从 MVC Controller 返回 Json 对象以查看

jquery - AJAX 将 JavaScript 字符串数组发布到 JsonResult 作为

java - 可以将 Jackson 配置为从所有字符串属性中修剪前导/尾随空格吗?

json - 使用 jq 从 JSON 输出中提取特定字段

javascript - 如何转换为 D3 的 JSON 格式?

php - 使用 json_encode() 时删除数组索引引用

json - 在 node package.json 中,使用额外参数从另一个脚本调用脚本,在这种情

json - 应该如何为 RESTful JSON 集合实现 HATEOAS 样式的链接?

ruby-on-rails - 销毁记录时应该渲染什么?