我想知道是否有任何方法来注释Entity getter,使ResponseBuilder只显示具有该特定注释的那些。
目前我开发了一个REST api,我有一个包含6个字段的实体,我想在GET请求中只显示其中的3个。我想到的唯一解决方案是在实体类上创建一个包装器,它只包含我希望在响应中显示的信息的getter。但在此之前,我想知道是否还有其他办法。
这就是我目前提供回复的方式。
Response.ok(device).build();
这就是我的实体的样子:
@Entity
@XmlRootElement
@IdClass(DevicePK.class)
public class Device implements Serializable {
private static long serialVersionUID = 1l;
@Id
private String deviceId;
private String ssoId;
@Temporal(TemporalType.TIMESTAMP)
private Date createdAt;
@Temporal(TemporalType.TIMESTAMP)
private Date lastUpdateAt;
@Id
@Enumerated(EnumType.STRING)
private Platform platform;
@Temporal(TemporalType.TIMESTAMP)
private Date associationDate;
/**
* @return the deviceId
*/
public String getDeviceId() {
return deviceId;
}
/**
* @param deviceId the deviceId to set
*/
public void setDeviceId(String deviceId) {
this.deviceId = deviceId;
}
/**
* @return the ssoId
*/
public String getSsoId() {
return ssoId;
}
/**
* @param ssoId the ssoId to set
*/
public void setSsoId(String ssoId) {
this.ssoId = ssoId;
}
/**
* @return the createdAt
*/
public Date getCreatedAtAsDate() {
return createdAt;
}
/**
* @param createdAt the createdAt to set
*/
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
/**
* @return the lastUpdateAt
*/
public String getLastUpdateAt() {
return lastUpdateAt;
}
/**
* @param lastUpdateAt the lastUpdateAt to set
*/
public void setLastUpdateAt(Date lastUpdateAt) {
this.lastUpdateAt = lastUpdateAt;
}
/**
* @return the platform
*/
public Platform getPlatform() {
return platform;
}
/**
* @param platform the platform to set
*/
public void setPlatform(Platform platform) {
this.platform = platform;
}
/**
* @return the associationDate
*/
public String getAssociationDate() {
return associationDate;
}
/**
* @param associationDate the associationDate to set
*/
public void setAssociationDate(Date associationDate) {
this.associationDate = associationDate;
}