Jackson: Ignore Json configuration value

后端 未结 2 1524
夕颜
夕颜 2020-12-13 06:41

I have the following json file:


{
  \"segments\": {        
            \"externalId\": 123, 
            \"name\": \"Tomas Zulberti\", 
            \"shoul         


        
相关标签:
2条回答
  • 2020-12-13 07:16

    Also we can use mapper.enable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES); instead @JsonIgnoreProperties(ignoreUnknown=true)

    but for particular property we can use

    @JsonIgnoreProperties({"externalId"})
    public class Segment {
    
        private String id;
        private String name;
        private boolean shouldInform;
    
        // getter and setters here...
    }
    
    0 讨论(0)
  • 2020-12-13 07:34

    You can use annotation @JsonIgnoreProperties; if it's just one value you want to skip, something like:

    @JsonIgnoreProperties({"externalId"})
    

    or to ignore anything that can't be used:

    @JsonIgnoreProperties(ignoreUnknown=true)
    

    There are other ways to do it too, for rest check out FasterXML Jackson wiki.

    0 讨论(0)
提交回复
热议问题