我有一个包含几个属性和一个列表的 bean。例如
public class Person {
@XmlElement
public String getName() { }
@XmlElement
public List getFriends() { }
}
我现在想要一个界面,有时会返回一个人与他们的朋友的列表,有时没有:
@GET
@Path("getPersonOnly")
public List<Person> getPersonOnly();
@GET
@Path("getPersonWithFriends")
public List<Person> getPersonWithFriends();
这些方法的实现非常相似。唯一的区别是其中一个不会包含在返回的 xml 中的好友列表中。
关于如何解决这个问题的任何想法?我最初的想法是将 Person 子类化为 PersonWithNoFriends ,它不会对 getFriends 进行注释。
谢谢,
阿萨夫