JaxB クラスを使用する方法があり、Object Model を JaxB クラスに渡すことができ、JaxB クラスは URI を生成します。以下は小さな試作品です。
UserResource クラス
@Path("/user")
public class UserResource {
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{user-id}")
public UserJaxB getUser(@PathParam("user-id") String userId, @Context
HttpServletRequest request) {
// now XYZ is hard-coded value
String serviceEndpoint = request.getContextPath() + "/" + "user";
UserModel userModel = new UserModel(userId, "XYZ");
return new UserJaxB(serviceEndpoint,userModel);
}
}
ユーザー JAXB クラス
@XmlRootElement
public class UserJaxB {
private String name;
private String id;
private String serviceEndpoint;
private String URI;
public UserJaxB(String serviceEndpoint, UserModel userModel) {
this.name = userModel.getName();
this.id = userModel.getId();
this.serviceEndpoint = serviceEndpoint;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getURI() {
return this.serviceEndpoint + "/" + id;
}
}
ユーザー モデル クラス
public class UserModel {
String name;
String id;
public UserModel(String name, String id) {
this.name = name;
this.id = id;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
}