Suppose we have a class EntityEndpoint in Android Studio project called Project-AppEngine. We define a method to retrieve an entity by its key (represented as a String):
It would be useful if this was mentioned in the official documentation.
@ApiMethod(name = "getEntity”) public MyEntity getEntity( User user, @Named("key") String key ) throws OAuthRequestException { // ... }Then we generate client libraries:
- Tools -> Google Cloud Tools -> Generate Client Libraries
Remember, we need to do this twice as described at the end of Minimalistic GAE Endpoints in Android Studio post.
Then, in Project-endpoints/src/endpoint-src/java/com/example/package/entityendpoint/Entityendpoint.java, we'll have a problem. The method setKey(String) will be defined twice:
- The first method is for setting you API key
- The second method is for setting the key parameter we defined earlier.
To avoid this problem, we change our method definition to something like this
@ApiMethod(name = "getEntity”) public MyEntity getEntity( User user, @Named(“id”) String key ) throws OAuthRequestException { // ... }or like this
@ApiMethod(name = "getEntity”) public MyEntity getEntity( User user, @Named(“id”) String id ) throws OAuthRequestException { // ... }Then the second generated client method will change its name to setId(String).
It would be useful if this was mentioned in the official documentation.
No comments:
Post a Comment