Jackson JSON Marshall ignore getter

JsonJackson

Json Problem Overview


Im using Jackson 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.

Basic usecase (I want to ignore the 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;
}

}

Json Solutions


Solution 1 - Json

That would be @JsonIgnore on getter method.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiontarkaView Question on Stackoverflow
Solution 1 - JsonStaxManView Answer on Stackoverflow