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.
精彩评论