我想获得一个列表,基本上是使用泽西的RESTful API(服务器和客户端)新泽西ClientResponse获取的实体组的列表
UserRESTClient client = new UserRESTClient();
ClientResponse response = client.getUsersByType(ClientResponse.class, String.valueOf(userType));
List<User> participants = response.getEntity(new GenericType<List<User>>() {
});
然而实体列表的结果,上面的代码不工作如果实体用户有一个组合对象,如果例如,
public class User {
private UserId userId;
}
public class UserId {
private int id;
private int categoryId;
}
在这种情况下,JSON被反序列化泽西和字段类型用户ID类用户内部返回null。我检查了返回的JSON,并且在RESTful Server端的一切看起来不错,但嵌套的JSON响应在客户端没有明确处理。
任何帮助将不胜感激。我不确定是否因为杰克逊预处理器。
以下是实际的代码片段。它涉及两个参与者类别和ParticipantPK(每个参与者的主要参与者)。
@Entity
@Table(name = "conference_participant")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Participant.findAll", query = "SELECT p FROM Participant p"),
public class Participant implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
protected ParticipantPK participantPK;
}
@Embeddable
public class ParticipantPK implements Serializable {
@Basic(optional = false)
@NotNull
@Column(name = "conference_id")
private int conferenceId;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 150)
@Column(name = "participant_sip_uri")
private String participantSipUri;
public ParticipantPK() {
}
public ParticipantPK(int conferenceId, String participantSipUri) {
this.conferenceId = conferenceId;
this.participantSipUri = participantSipUri;
}
和代码检索ClientResponse,
List<Participant> participants = response.getEntity(new GenericType<List<Participant>>() {
});
然而,ParticipantPK(复合PK)为空。
嗨马丁,非常感谢你的努力。我正在使用@@ Entity @@ XmlRootElement。您可以回顾一下该类代码片段的问题吗? – blacks0ul 2012-03-15 23:18:04
我正在使用1.12 – blacks0ul 2012-03-16 00:47:26
您在服务器端使用了哪个容器?如果GlassFish,哪个版本?客户端是否也部署为Web应用程序?或者它是一个桌面/命令行应用程序? – 2012-03-16 01:06:26