ozi*_*jnr 2 java google-app-engine enums serialization google-cloud-platform
我有以下Enum类
public enum EventAccess {
PUBLIC("PUBLIC"),
EMPLOYEES_ONLY("EMPLOYEES_ONLY"),
String name;
private EventAccess(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
Run Code Online (Sandbox Code Playgroud)
此外,我有一个Serializable类,其枚举作为其中一个字段
public class EventAccessRequest implements Serializable{
private List<EventAccess> event_access = new ArrayList<>();
public EventAccessRequest() {
}
public List<EventAccess> getEvent_access() {
return event_access;
}
public void setEvent_access(List<EventAccess> event_access) {
this.event_access = event_access;
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个@Api方法,它创建了一个EventAccessRequest类型的对象.我在Api Explorer中设置了此请求的值,但它没有设置我放入的任何枚举字段.
@ApiMethod(name = "fetchEventByEventAccess", path = "user/events/list-by-access/", httpMethod = HttpMethod.GET)
public RestfulResponse fetchEventByEventAccess(EventAccessRequest request)throws Exception
{
EventAccess x = request.getEvent_access().get(0);
return new RestfulResponse(Status.SUCCESS, "Events retrieved",request, 200);
}
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试插入其他不是枚举的类型并设置它们的值,但是当我尝试在Api中插入枚举时,没有设置值.所以我的请求对象总是空的.
可能是什么问题呢?
错误是您使用httpMethod = HttpMethod.GET而不是httpMethod = HttpMethod.POST,因为您正在发送付费加载请求,您将需要使您的http方法等待发布请求接受有效负载或请求正文
所以它应该是
@ApiMethod(name = "fetchEventByEventAccess", path = "user/events/list-by-access/", httpMethod = HttpMethod.POST)
Run Code Online (Sandbox Code Playgroud)
观察httpMethod谢谢.
归档时间: |
|
查看次数: |
39 次 |
最近记录: |