我想通过REST调用使用Jersey来获取Java对象。 问题:如果A具有所有B的成员,我可以发送A类的对象并接收B类的对象吗?泽西岛对象映射
让我给个例子:
class A {
String one;
Date two;
int three;
}
class B {
Date two;
int three;
}
比方说,我有一个REST服务:
class MyREST {
@GET
@Path("somepath")
public void getThing() {
return new A();
{
,我和一个代码调用它:
Client client = Client.create();
WebResource scResource = client.resource("somePath");
MyClass result = scResource.type(MediaType.APPLICATION_JSON_TYPE).accept(MediaType.APPLICATION_JSON_TYPE).get(B.class);
谢谢。如果B扩展A,它会工作吗? – sunny 2012-07-18 13:33:40
类之间的关系与它有任何关系。请检查我的答案。 – 2012-07-18 16:02:00