对于我的 Genson 配置,我使用 UrlQueryParamFilter
。它有效,但不像我预期的那样。
我的实体:
public class Root {
private String firstRootProp;
private String secondRootProp;
private List<Child> childs;
//getters & setters
}
public class Child {
private String firstChildProp;
private String secondChildProp;
//getters & setters
}
“rootEntity”端点绑定(bind)到获取一些Root
以我的休息服务为例。
当我得到http://<host>/myservice/rootEntity?filter=childs
时我预计将获得所有 child 以及所有 child 的属性(property)。但实际上我只得到了 child 的结构:
{
"childs": [
{},
{}
]
}
我想要得到什么:
{
"childs": [
{
"firstChildProp": "Some value for first property",
"secondChildProp": "And some value for second property"
},
{
"firstChildProp": "Some value for first property",
"secondChildProp": "And some value for second property"
}
]
}
如何修复它?
谢谢。
最佳答案
UrlQueryParamFilter 希望您提供要包含的所有属性的名称(如果配置为排除属性,则要排除)。简而言之,做 http://<host>/myservice/rootEntity?filter=childs,firstChildProp,secondChildProp
应该可以。
我想提供一种配置包含所有子属性的方法可能是有意义的,我打开了这个问题https://github.com/owlike/genson/issues/105 .
关于java - Genson:使用 RuntimePropertyFilter 时处理子属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39532752/