Jackson JSON Marshall 忽略 getter

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13533629/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 18:38:05  来源:igfitidea点击:

Hymanson JSON Marshall ignore getter

jsonHymanson

提问by tarka

Im using Hymanson to convert a POJO into a JSON to store in the DB. However I have a getter that I want to ignore. I have see a lot of info relating to @JsonIgnoreProperties but I can't seem to make any progress with it. I basically want the equivalent of @Transient.

我使用 Hymanson 将 POJO 转换为 JSON 以存储在数据库中。但是我有一个我想忽略的吸气剂。我已经看到很多与 @JsonIgnoreProperties 相关的信息,但我似乎无法取得任何进展。我基本上想要相当于@Transient。

Basic usecase (I want to ignore the InternationalNumber):

基本用例(我想忽略 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;
}

}

回答by StaxMan

That would be @JsonIgnoreon getter method.

那将是@JsonIgnoregetter方法。