@JsonIgnoreType

@JsonIgnoreType is used to mark all properties of annotated type to be ignored.

Let's use the annotation to mark all properties of type Name to be ignored

public class User {

    public int id;

    public Name name;

    @JsonIgnoreType
    public static class Name{
        public String firstName;

        public String lastName;
    }
}

Here's the simple test making sure the ignore works correctly:

    @Test
    public void test01() throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();
        User user = new User();
        user.id =1;
        User.Name name = new User.Name();
        name.firstName = "Jiang";
        name.lastName = "Lei";
        user.name = name;

        String s = mapper.writeValueAsString(user);
        System.out.println(s);
    }
    /*
    output:{"id":1}
    */

results matching ""

    No results matching ""