gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 21:52:58 31 4
gpt4 key购买 nike

我正在使用 Google App engine1.9.3、Eclipse、Objectify5.03。我的类(class)如下:

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

}

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

这是我第一次尝试 Objectify。

任何想法我做错了什么。从我目前所读的内容来看,GAE 端点和 Objectify 应该可以工作,对吗?

最佳答案

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

这是 Cloud Endpoints 的已知限制,因为它不允许使用自定义对象。如果您有兴趣,请特别关注这一点:Cloud endpoints .api generation exception when using objectify (4.0b1) parameterized key

您必须使用 @ApiResourceProperty 注释您的方法并将其忽略的属性设置为 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(){
}
}

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

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

但在我看来,更好的方法是重新考虑您的类(class)设计,或者更确切地说,重新考虑您要尝试做什么。

关于eclipse - GAE+Objectify - 不支持参数化类型 com.googlecode.objectify.Ref,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24590518/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com