Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google app engine Google应用程序引擎-获取整个实体组的JSON_Google App Engine_Google Cloud Endpoints_Objectify - Fatal编程技术网

Google app engine Google应用程序引擎-获取整个实体组的JSON

Google app engine Google应用程序引擎-获取整个实体组的JSON,google-app-engine,google-cloud-endpoints,objectify,Google App Engine,Google Cloud Endpoints,Objectify,我的应用程序中有一个实体关系,使用@Parent注释形成实体组 import com.googlecode.objectify.annotation.Entity; 导入com.googlecode.objectify.annotation.Id; 导入com.googlecode.objectify.annotation.Parent; @实体 公共阶层人士{ @Id长Id; 字符串名; } @实体 公车{ @父密钥所有者; @Id长Id; 字符串颜色; } 我正在使用谷歌云端点创建一个R

我的应用程序中有一个实体关系,使用@Parent注释形成实体组

import com.googlecode.objectify.annotation.Entity;
导入com.googlecode.objectify.annotation.Id;
导入com.googlecode.objectify.annotation.Parent;
@实体
公共阶层人士{
@Id长Id;
字符串名;
}
@实体
公车{
@父密钥所有者;
@Id长Id;
字符串颜色;
}
我正在使用谷歌云端点创建一个RESTFul服务。我想在我的资源中创建一个GET,它不仅为父级而且为整个实体组返回JSON。做这件事的好方法是什么

我现在拥有的是

@ApiMethod(
    name = "persons.get",
    httpMethod = HttpMethod.GET,
    path = "persons/{id}"
 )
public Person get(@Named("id") String webSafeKey) {

    Key<Person> key = Key.create(webSafeKey);
    Person person= ofy().load().key(key).safe();

    return person;

}
@ApiMethod(
name=“persons.get”,
httpMethod=httpMethod.GET,
path=“persons/{id}”
)
公众人物获取(@Named(“id”)字符串webSafeKey){
Key=Key.create(webSafeKey);
Person-Person=ofy().load().key(key).safe();
返回人;
}
这将返回person的JSON,但是如果我希望包含person汽车的JSON,该怎么办呢。可能是person对象中的getter和setters getCars()之类的内容。我想知道是否有更好的办法

--更新--


此外,在getter和setter中,似乎没有一种好的方法可以返回非文本的对象,也不能在没有适配器的情况下转换为JSON。

我个人发现,端点的方法只是让我走了这么远。我还需要一种发送/接收任意实体组的方法。因此,我创建了一对端点,用于发送/接收如下类:

public class DataParcel implements Serializable {
  public Integer operation = -1;
  private static final long serialVersionUID = 1L;
  public List<String> objects = null;   // new ArrayList<String>();
}
公共类DataParcel实现可序列化{
公共整数运算=-1;
私有静态最终长serialVersionUID=1L;
public List objects=null;//新建ArrayList();
}
这些对象是我的任何实体的JSON实例。因此,对于您的情况,您的“get”方法可以返回数据包;您的实现将把一个人和任意数量的汽车加载到DataParcel实例中,并将其返回给客户端


(Serializable与您的问题无关-它允许我将其放入任务队列中以供以后处理。)

就我个人而言,我发现端点的处理方式只让我走了这么远。我还需要一种发送/接收任意实体组的方法。因此,我创建了一对端点,用于发送/接收如下类:

public class DataParcel implements Serializable {
  public Integer operation = -1;
  private static final long serialVersionUID = 1L;
  public List<String> objects = null;   // new ArrayList<String>();
}
公共类DataParcel实现可序列化{
公共整数运算=-1;
私有静态最终长serialVersionUID=1L;
public List objects=null;//新建ArrayList();
}
这些对象是我的任何实体的JSON实例。因此,对于您的情况,您的“get”方法可以返回数据包;您的实现将把一个人和任意数量的汽车加载到DataParcel实例中,并将其返回给客户端


(Serializable与您的问题无关-它允许我将其放入任务队列中以供以后处理。)

在person对象中使用汽车id,并在加载person对象时加载它怎么样

@Entity
public class Person {
    @Id Long id;
    String name;
    Ref<Car> car;
}

@Entity
public class Car {
    @Parent Key<Person> owner;
    @Id Long id;
    String color;
}
public Person get(@Named("id") String webSafeKey) {

    Key<Person> key = Key.create(webSafeKey);
    Person person= ofy().load().key(key).safe();
    return person;

}

在person对象中使用car id并在加载person对象时加载它怎么样

@Entity
public class Person {
    @Id Long id;
    String name;
    Ref<Car> car;
}

@Entity
public class Car {
    @Parent Key<Person> owner;
    @Id Long id;
    String color;
}
public Person get(@Named("id") String webSafeKey) {

    Key<Person> key = Key.create(webSafeKey);
    Person person= ofy().load().key(key).safe();
    return person;

}

如果您不使用实体组,这似乎是一种方式,但实际上,请定义两次关系??我不太确定,但现在你提起了,我真的不知道为什么不。虽然我会在Ref上使用@Load。这与我面临的问题是一样的。除了双向定义关系,我找不到其他解决方案。可能是因为关系数据库的经验,这似乎是一个问题。如果你不使用实体组,这似乎是一种方式,但实际上,定义关系两次??我不太确定,但现在你提起了,我真的不知道为什么不。虽然我会在Ref上使用@Load。这是我面临的同一个问题。除了双向定义关系之外,我找不到其他解决方案。可能是因为关系数据库的经验,这似乎是一个问题。