小编cvi*_*igo的帖子

Objectify List <Ref <T >>未由Google App Engine端点序列化

您有两个相关的实体:客户和汽车.每个客户可以拥有多辆汽车

这是实体的摘要视图:

public class Customer 
{
    //Inner classes for partial loads
    public static class NoCars{}

    @Id protected String id;
    private String fullName;
    @Load(unless=NoCars.class) private List<Ref<Car>> cars;
}

public class Car
{
    @Id private Long id;
    private String makeAndModel;
    private String plateNumber;
}
Run Code Online (Sandbox Code Playgroud)

这是一种从数据存储区他拥有的所有汽车中检索客户的方法:

public Customer getCustomer(@Named("id") String customerId)
{
    Customer customer =  ofy().load().type(Customer.class).id(customerId).now();
    if (customer==null)
        throw new NotFoundException("customer not found");
    else
        return customer;
}
Run Code Online (Sandbox Code Playgroud)

endpoints.sh无法实现这一点,因为不支持List <Ref<Car>>返回类型Customer中包含的类型,但我发现这个有趣的解决方法:

我创建了CustomerPOJO

public class CustomerPOJO …
Run Code Online (Sandbox Code Playgroud)

java google-app-engine json endpoints objectify

6
推荐指数
1
解决办法
1354
查看次数

标签 统计

endpoints ×1

google-app-engine ×1

java ×1

json ×1

objectify ×1