Filter nested objects using Jackson's BeanPropertyFilter

前端 未结 2 916
灰色年华
灰色年华 2021-01-11 20:29

I have the following objects:

@JsonFilter(\"myFilter\")
public class Person {
    private Name name;
    private int age;
    public Name getName() {return n         


        
2条回答
  •  猫巷女王i
    2021-01-11 21:14

    Ok, figured it out. Varargs would have made this a bit prettier, but oh well. Just hope I don't have two inner beans which have properties with the same name. I wouldn't be able to make the distinction between the two

        FilterProvider filters = new SimpleFilterProvider()
                .addFilter("myFilter", SimpleBeanPropertyFilter
                        .filterOutAllExcept(new HashSet(Arrays
                                .asList(new String[] { "name", "firstName" }))));
    

提交回复
热议问题