Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Entity arguments in Google Cloud Endpoints

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.

like image 365
aez Avatar asked Apr 29 '26 00:04

aez


1 Answers

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;
  // ...
}
like image 164
Dan Holevoet Avatar answered May 01 '26 07:05

Dan Holevoet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!