开发者

RESTEASY - returning the same object with and without a list

开发者 https://www.devze.com 2023-02-21 01:56 出处:网络
I have a bean that includes several properties and a list. E.g. public class Person { @XmlElement public String getName() { }

I have a bean that includes several properties and a list. E.g.

public class Person {
    @XmlElement
    public String getName() { }

    @XmlElement
    public List getFriends() { }
}

I now want to have an interface that sometimes returns a list of Persons with their friends sometimes without:

@GET
@Path("getPersonOnly")
public List<Person> getPersonOnly();

@GET
@Path("getPersonWithFriends")
public List<Person> getPersonWithFriends();

The implementation of these methods is very similar. The only difference is that one of them will not include in the xml r开发者_Python百科eturned the list of friends.

Any ideas on how to solve this? My initial thought was to subclass Person to PersonWithNoFriends which will not have the getFriends annotated.

Thanks,

Assaf


In your getPersonOnly(), load the person, setFriends to NULL and the element won't be in the output.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号