当我在api资源管理器中测试我的google端点API时,saveProfile方法会抛出503 Service Unavailable
错误,但所有其他方法都可以正常工作。
以下是我的终端中的 saveProfile 方法:
@ApiMethod(name = "saveProfile")
public Profile saveProfile(final ProfileForm profileForm) {
String firstName = profileForm.getFirstName();
String lastName = profileForm.getLastName();
String email = profileForm.getEmail();
Profile profile = new Profile("124234132", email, firstName, lastName);
ofy().save().entity(profile).now();
return profile;
}
以下是个人资料实体类:
@Entity
public class Profile {
@Id
private String userId;
private String email;
private String firstName;
private String lastName;
public Profile(String userId, String email, String firstName, String lastName) {
this.userId = userId;
this.email = email;
this.firstName = firstName;
this.lastName = lastName;
}
}
以下是 profileForm 类:
public class ProfileForm {
private String firstName;
private String lastName;
private String email;
public ProfileForm() {}
public ProfileForm(String firstName, String lastName, String email) {
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public String getEmail() {
return email;
}
}
我已经注册了该实体,并设置了API_EXPLORER_CLIENT_ID
以及Web和Android客户端ID。
有人理解如何解决这个问题,以便该方法只返回配置文件对象吗?
答案 0 :(得分:1)
为了使Profile可序列化,您需要为每个字段定义getter和setter(例如getUserId(),setUserId(string Id))。
Objectify实体还必须包含一个无参数构造函数:https://github.com/objectify/objectify/wiki/Entities
如果能解决错误,请告诉我。