Multiple Entity arguments in Google Cloud Endpoints

纵饮孤独 提交于 2019-11-27 21:58:42

问题


How can I pass more than one Entity from a client to a Google Cloud Endpoint?

For example, passing a single Entity is easily done in an Endpoint api source file in the server:

public class SomeEndpoint {
...
   @ApiMethod(...)
   public MyEntity someMethod(MyEntity someEntity) {
   ...
   }
...
}

then in a client I could easily call

endpoint.someMethod(someEntity).execute()

But, what if I want to pass two entities to an endpoint?, like this:

 @ApiMethod(...)
 public MyEntity otherMethod(MyEntity someEntity, MyEntity someOtherEntity) {
    ...
 }

this doesn't work, GPE only generates an endpoint library with a single MyEntity argument.

Is it possible to pass multiple Entity arguments?

Thanks.


回答1:


You can't send multiple entity types in the body of your request. You'll need to create a wrapper entity that contains those two entities, e.g.:

class MyWrapperEntity {
  MyEntity someEntity;
  MyOtherEntity someOtherEntity;
  // ...
}

However, that's not what your example shows (the entities are the same type). Use a List<MyEntity> or Map<String, MyEntity> inside of a collection entity instead, e.g.:

class MyEntityCollection {
  List<MyEntity> items;
  // ...
}



回答2:


Use the 'named' annotation...

@ApiMethod(name = "sendStuff")
public void sendStuff( @Named("clientId") String clientId, @Named("stuff") String stuff )

And for android, the client code would look like this

SendStuff sl = service.sendStuff( clientId, stuff );


来源:https://stackoverflow.com/questions/15450472/multiple-entity-arguments-in-google-cloud-endpoints

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!