GAE + Objectify - 参数化类型com.googlecode.objectify.Ref不受支持

Dav*_*idC 2 eclipse google-app-engine objectify google-cloud-endpoints

我正在使用Google App engine1.9.3,Eclipse,Objectify5.03.我的班级如下:

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 

}
Run Code Online (Sandbox Code Playgroud)

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

这是我第一次尝试Objectify.

我有什么不妥的想法.从我到目前为止所阅读的内容来看,GAE端点和Objectify应该有效,对吗?

elc*_*cid 10

Google Cloud Endpoints无法序列化Ref对象,因为它是由其定义的任意对象objectify,因此不支持错误.

这是Cloud Endpoints的已知限制,因为它不允许使用自定义对象.如果您感兴趣,在这一点上有一个完整的讨论主题:使用objectify(4.0b1)参数化键时的云端点.api生成异常

您必须使用注释方法@ApiResourceProperty并将其ignore属性设置为,true如下面的代码所示:

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(){
    }
}
Run Code Online (Sandbox Code Playgroud)

如果您仍想使用这些对象中保存的数据,请考虑在类中添加一些字段来保存数据,并在User类完成加载后将其初始化,如下所示:

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

但在我看来,更好的方法是重新考虑你班级的设计,或者更重新思考你想要做的事情.