Daily Archives: June 11, 2019

@JsonIgnoreProperties

@JsonIgnoreProperties is used in jackson deserialization. When a json file is deserialized to a class, it is ok that field is missing. For example, we have class A:

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class A {

    @JsonProperty
    int a;

    @JsonProperty
    int b;
}

 

It is ok to deserialize {“a”:1}, which misses field b.

But it is not ok to deserialize {“a”:1, “b”:2, “c”:3}

In order to be able to deserialize a stream with unknown field, we need to use @JsonIgnoreProperties annotation:

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class A {

    @JsonProperty
    int a;

    @JsonProperty
    int b;
}