GAE + Objectify - 不支持参数化类型com.googlecode.objectify.Ref [英] GAE+Objectify - Parameterized type com.googlecode.objectify.Ref not supported

查看:184
本文介绍了GAE + Objectify - 不支持参数化类型com.googlecode.objectify.Ref的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google App Engine1.9.3,Eclipse,Objectify5.03。我的课程如下:

I am using Google App engine1.9.3, Eclipse, Objectify5.03. My Class is as follows:

import com.googlecode.objectify.Ref;
import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;
import com.googlecode.objectify.annotation.Load;

@Entity
public class User {

@Id private Long userId;
private String userName;
@Load private Ref<UserDetails> userDetails;
@Load private Ref<UserPassword> userPassword;

//getters & setters 

}

当我尝试通过这个类创建google端点Eclipse,我得到以下错误:
java.lang.IllegalArgumentException:参数化类型com.googlecode.objectify.Ref不支持

When I try creating the google endpoint for this class thru Eclipse, I get the following error: java.lang.IllegalArgumentException: Parameterized type com.googlecode.objectify.Ref not supported

这是我第一次尝试Objectify。

This is my first attempt at Objectify.

任何想法我做错了什么。从目前为止,我已经阅读过的任何GAE端点和Objectify应该可以正常使用?

Any ideas what I am doing wrong. From whatever I have read so far GAE endpoints and Objectify should work, correct?

推荐答案

Google Cloud Endpoints无法将 Ref 对象,因为它是由 objectify 定义的任意对象,因此不支持错误指示。

Google Cloud Endpoints is unable to serialise the Ref object because it is an arbitrary object defined by objectify, therefore not supported as the error indicates.

这是已知的限制云端点,因为它不允许使用自定义对象。在这一点上有一个整体的讨论线索,特别是如果你有兴趣的话:云端点.api一代使用objectify(4.0b1)参数化键时出现异常

This is known limitation with Cloud Endpoints in that it does not allow custom objects to be used. There is a whole discussion thread on this point in particular if you're interested: Cloud endpoints .api generation exception when using objectify (4.0b1) parameterized key

您将不得不使用 @ApiResourceProperty 并将其忽略的属性设置为 true ,如下面的代码所示:

You will have to annotate your methods with @ApiResourceProperty and set its ignored attribute to true as illustrated in the code below:

import com.googlecode.objectify.Ref;
import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;
import com.googlecode.objectify.annotation.Load;
import com.google.api.server.spi.config.AnnotationBoolean;
import com.google.api.server.spi.config.ApiResourceProperty;

@Entity
public class User 
{
    @Id private Long userId;
    private String userName;
    @Load private Ref<UserDetails> userDetails;
    @Load private Ref<UserPassword> userPassword;

    //getters & setters
    @ApiResourceProperty(ignored = AnnotationBoolean.TRUE) 
    public UserDetail getUserDetails(){
    }

    @ApiResourceProperty(ignored = AnnotationBoolean.TRUE) 
    public UserPassword getUserPassword(){
    }
}

如果您还想使用这些对象中保存的数据,然后考虑添加一些字段到您的类来保存数据并在您的用户类完成加载之后对其进行初始化:

If you still want to use the data held in those objects then consider adding some fields to your class to hold the data and initialise them after your User class has finished loading like so:

@Ignore String firstName;
@OnLoad
void trackUserDetails() 
{ 
    this.firstName = getUserDetails().getFirstName(); 
    // add more code here to set other fields, you get the gist
}

但在我看来,一个更好的方法是重新考虑你的班级的设计,或者反思你想要做什么。

But in my opinion a better approach would be to reconsider the design of your class, or rather rethink what you're trying to do.

这篇关于GAE + Objectify - 不支持参数化类型com.googlecode.objectify.Ref的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆