-3

I have a json entry like :

{
    "name" : "tom"
    "age" : 10
}

Some json entries have an additional field of address.

I'm trying to read it to a POJO defined as follows :

public class StudentDetails {


    @NonNull
    private final String name;

    @NonNull
    private final int age;

    private final String address;

I'm unable to deserialise this. What Jackson annotation can I use to accomplish this ? Some of the entries will have the field of address whereas others won't.

Tried using @NonNull, @Nullable, @JsonIclude, @JsonIgnoreProperities, Optional<>

1 Answers1

0

Try to use this:

@JsonInclude(JsonInclude.Include.NON_NULL)

This indicates that only properties with non-null values are to be included.

  • `@JsonInclude(JsonInclude.Include.NON_NULL)` is only effective during serialization and not during deserialization (which is what I'm interested in) – Reshu Bisht Nov 04 '22 at 14:39