Search code examples
javajsongenson

Genson: Handling child's properties while using RuntimePropertyFilter


For my Genson configuration I used UrlQueryParamFilter. And it works, but not as I expected.
My entities:

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" endpoint binded to getting some Root instatnce in my rest service. When I get http://<host>/myservice/rootEntity?filter=childs I excpected will get the all childs with all child's properties. But actually I got child's structure only:

{
    "childs": [
        {},
        {}
    ]
}

And what I want to get:

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

How can I fix it?
Thx.


Solution

  • The UrlQueryParamFilter expects you to provide the name of all the properties you want to include (or exclude if configured to exclude properties). So in short doing http://<host>/myservice/rootEntity?filter=childs,firstChildProp,secondChildProp should work.

    I guess it could make sense to provide a way to configure the inclusion of all child properties, I opened this issue https://github.com/owlike/genson/issues/105.