简体   繁体   English

泽西岛ClientResponse获取复合实体列表

[英]Jersey ClientResponse Get List of Composite Entities

I am trying to get a Result of a List, basically a list of entities using Jersey RESTful API (Server and Client) 我正在尝试获取列表结果,基本上是使用Jersey RESTful API(服务器和客户端)的实体列表

UserRESTClient client = new UserRESTClient();
ClientResponse response = client.getUsersByType(ClientResponse.class, String.valueOf(userType));
List<User> participants = response.getEntity(new GenericType<List<User>>() {
    });

However, the above code does not work if Entity User has a Composite Object, if for instance, 但是,如果实体用户具有复合对象(例如,

public class User {
  private UserId userId;
}
public class UserId {
  private int id;
  private int categoryId;
}

In this case, the JSON is deserialized by Jersey and returned null for the field type UserId inside Class User. 在这种情况下,Jersey将反序列化JSON,并为类User中的字段ID UserId返回null。 I inspected the JSON returned and everything seems good at the RESTful Server end, but the nested JSON response is not clearly processed at the Client. 我检查了返回的JSON,并且在RESTful Server端一切看起来都不错,但是嵌套的JSON响应在客户端未得到明确处理。

Any help would be greatly appreciated. 任何帮助将不胜感激。 I am not sure if it because of the Jackson preprocessor. 我不确定是否是因为Jackson预处理程序。

Following is the actual Code Snippet. 以下是实际的代码段。 It involves two classes Participant and ParticipantPK (primary for each Participant). 它涉及两个类别的参与者和参与者PK(每个参与者主要)。

@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;
    }

And the Code for retrieving ClientResponse, 还有用于检索ClientResponse的代码,

 List<Participant> participants = response.getEntity(new GenericType<List<Participant>>() {
    });

However, the ParticipantPK (Composite PK) is null. 但是,ParticipantPK(复合PK)为空。

You only pasted a code snippet so I don't know if this part is excluded, but in my code I didn't have setters for the fields. 您仅粘贴了一个代码段,所以我不知道是否排除了这部分,但是在我的代码中,我没有用于字段的设置器。 I had getters, but no setters. 我有吸气剂,但没有吸气剂。

Without the setters, my composite objects themselves were non-null, but the members of those objects were themselves null. 没有setter,我的合成对象本身为非null,但是这些对象的成员本身为null。

I tried to reproduce it, but using the same data structures worked for me. 我试图重现它,但是使用相同的数据结构对我有用。 What version of Jersey are you using? 您正在使用哪个版本的Jersey? Is User class annotated with @XmlRootElement or are you using the POJO mapping feature? 是使用@XmlRootElement注释用户类,还是使用POJO映射功能?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM