2016-09-16 38 views
1

對於我的Genson配置,我使用了UrlQueryParamFilter。它有效,但不是我所期望的。
我的實體:Genson:在使用RuntimePropertyFilter時處理孩子的財產

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」 端點綁定到得到一些Root instatnce在我休息的服務。 當我得到http://<host>/myservice/rootEntity?filter=childs我感到遺憾的是會得到所有孩子的所有孩子的財產。但實際上我只拿到了孩子的結構:

{ 
    "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" 
     } 
    ] 
} 

我怎樣才能解決呢?
Thx。

回答

1

UrlQueryParamFilter期望您提供要包含的所有屬性的名稱(或者如果配置爲排除屬性,則排除)。所以總之要做http://<host>/myservice/rootEntity?filter=childs,firstChildProp,secondChildProp應該可以工作。

我想這可能是有道理的提供一種方法來配置包含所有子屬性,我打開此問題https://github.com/owlike/genson/issues/105

相關問題