Jackson注解 @JsonIgnore

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012326462/article/details/83004910

@JsonIgnore的作用是忽略这个属性不被序列化或者反序列化,不管是作用于get方法,set方法还是field属性字段,都是一样的。

    @JsonIgnore
    private Date birthday;
    @Test
    public void testJson7() throws Exception{
        Person person = new Person("ABD");
        person.setAddress("河北省");
        person.setName("xuhaixing");
        person.setBirthday(new Date());
        String s = mapper.writeValueAsString(person);
        System.out.println(s);
        String str = "{\"id\":\"ABD\",\"name\":\"xuhaixing\",\"birthday\":1539183966844,\"address\":\"河北省\"}";
        Person person1 = mapper.readValue(str, Person.class);
        System.out.println(person1);
    }

猜你喜欢

转载自blog.csdn.net/u012326462/article/details/83004910