Sha*_*aun 7 java google-app-engine google-cloud-endpoints
为什么Google Cloud Endpoints存在此限制:
Arrays or collections of entity types are not allowed.
Run Code Online (Sandbox Code Playgroud)
对于带有方法的API:
@ApiMethod(name = "getCollection", path = "getCollection", httpMethod = HttpMethod.POST)
public ArrayList<MyObject> getCollection(List<MyObject> pMyObjects) {
Run Code Online (Sandbox Code Playgroud)
什么是解决这个问题的最佳方法?谢谢!
我认为它不受支持的原因是因为方法签名中的命名参数最终是URL查询参数,并且他们不希望用长项目列表污染它.此外,它们仅支持签名中的实体类型的单个对象,因为它自动成为"请求主体".您可以在文档中阅读它.
至于解决它,你为"请求体"创建一个容器实体对象.这样做的好处是API Explorer将在GUI中扩展实体对象的各个部分,并帮助您正确地执行JSON.
这是一个添加名为"patchFieldOps"的Map以实现部分更新的示例.您可以根据需要将多个字段放入Entity对象中.我想如果你嵌入了更多用户定义的类型,他们还需要有@Entity注释.
@Entity
public class EndpointUpdateRequestBody {
// Since Google Cloud Endpoints doesn't support HTTP PATCH, we are overloading
// HTTP PUT to do something similar.
private Map<String, String> patchFieldsOps;
public EndpointUpdateRequestBody() {
patchFieldsOps = new HashMap<String, String>();
}
public EndpointUpdateRequestBody(Map<String, String> patchFieldsOps) {
this.patchFieldsOps = patchFieldsOps;
}
public Map<String, String> getPatchFieldsOps() {
return patchFieldsOps;
}
public void setPatchFieldsOps(Map<String, String> patchFieldsOps) {
this.patchFieldsOps = patchFieldsOps;
}
}
Run Code Online (Sandbox Code Playgroud)
...
@ApiMethod(
name = "stuff.update",
path = "stuff/{id}",
httpMethod = ApiMethod.HttpMethod.PUT
)
public Group update(
User apiUser,
@Named("id") String id,
@Nullable @Named("name") String name,
@Nullable @Named("description") String description,
EndpointUpdateRequestBody requestBody)
throws OAuthRequestException, InternalServerErrorException, NotFoundException,
BadRequestException, UnauthorizedException, ConflictException {
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2029 次 |
| 最近记录: |