Want to hide some fields of an object that are being mapped to JSON by Jackson

后端 未结 7 1900
北海茫月
北海茫月 2020-11-30 03:45

I have a User class that I want to map to JSON using Jackson.

public class User {
    private String name;
    private int age;
    prviate int securityCode;         


        
7条回答
  •  情深已故
    2020-11-30 04:17

    I had a similar case where I needed some property to be deserialized (JSON to Object) but not serialized (Object to JSON)

    First i went for @JsonIgnore - it did prevent serialization of unwanted property, but failed to de-serialize it too. Trying value attribute didn't help either as it requires some condition.

    Finally, working @JsonProperty with access attribute worked like a charm.

提交回复
热议问题