【发布时间】:2012-07-17 13:03:34
【问题描述】:
我想使用 Jersey 通过 REST 调用获取 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);
【问题讨论】: