过滤嵌套对象属性uisng @JsonFilter

问题描述

我经历了很多StackOverflow的问题和github的问题,但是没有得到我的问题的解决方案。 我上课如下:

@JsonFilter("apiFilter")
Class Employee{
    String id,String name;
    Address address,}
@JsonFilter("apiFilter")
Class Address{
    String id,String city,String state,String country,}   

我想在返回API的响应时使用@JosnFilter过滤Employee的属性及其嵌套对象Address属性在这里我可以使用下面的代码集过滤Employee的属性

SimpleBeanPropertyFilter propertyFilter = SimpleBeanPropertyFilter.filterOutAllExcept("name","address");
        
FilterProvider filters = new SimpleFilterProvider().addFilter("apiFilter",propertyFilter).setFailOnUnkNownId(false);

但是我还需要使用 dot(。)来过滤嵌套对象的属性,例如"address.city""address.state"将在filterOutAllExcept("address.state","address.city")中传递。我无法对地址使用其他过滤器,因为我需要根据对象引用dot(。)过滤其属性,例如address.state

我已经解决了这些github问题,但杰克逊对嵌套对象属性支持最近没有更新。

https://github.com/FasterXML/jackson-core/issues/230

https://github.com/FasterXML/jackson-databind/issues/1040

https://github.com/spring-projects/spring-framework/issues/17187

任何建议都会有很大帮助。。谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)