@Nullable @Named in GAE / Android pattern

I am trying to work on a sample GAE / Android application. There is a place facility.

There is a method in the created PlaceEndpoint class:

@ApiMethod(name = "listGame")
    public CollectionResponse<Place> listPlace(
            @Nullable @Named("cursor") String cursorString,
            @Nullable @Named("limit") Integer limit) {

        EntityManager mgr = null;
        Cursor cursor = null;
        List<Game> execute = null;

        try {
            mgr = getEntityManager();
            Query query = mgr.createQuery("select from Place as Place");
            if (cursorString != null && cursorString != "") {
                cursor = Cursor.fromWebSafeString(cursorString);
                query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
            }

            if (limit != null) {
                query.setFirstResult(0);
                query.setMaxResults(limit);
            }

            execute = (List<Game>) query.getResultList();
            cursor = JPACursorHelper.getCursor(execute);
            if (cursor != null)
                cursorString = cursor.toWebSafeString();

            // Tight loop for fetching all entities from datastore and accomodate
            // for lazy fetch.
            for (Game obj : execute)
                ;
        } finally {
            mgr.close();
        }

        return CollectionResponse.<Game> builder().setItems(execute)
                .setNextPageToken(cursorString).build();
    }

As I understand it, cursorand limitall the optional parameters.

However, I cannot figure out how to pass them using a Placeednpointclient-side class :

Placeendpoint.Builder builder = new Placeendpoint.Builder(AndroidHttp.newCompatibleTransport(), new JacksonFactory(), null);
builder = CloudEndpointUtils.updateBuilder(builder);
Placeendpoint endpoint = builder.build();

try {
    CollectionResponsePlace placesResponse = endpoint.listPlace().execute();
} catch (Exception e) {
    e.printStackTrace();

Normally, when params are not NULL, I would pass them in the endpoint.listPlace () method. But when the parameters are nullified, the client application does not see an alternative constructor that would accept the parameters.

How can I pass them then?

+4
source share
3 answers

. android, , REST , . , cursorstring:

@com.google.api.client.util.Key
      private String cursorstring;

      public String getCursorstring() {
        return cursorstring;
      }

      public ListPlace setCursorstring(String cursorstring) {
        this.cursorstring = cursorstring;
        return this;
      }

, endpoint Android, setCursorstring, :

CollectionResponsePlace placesResponse = endpoint.listPlace().setCursorstring("yourcursorstring").execute();
+9

. "" :

CollectionResponsePlace placesResponse = 
     endpoint.listPlace().set("cursor", "Your Cursorstring").execute();

+1

Faced the same problem, but a backend developed using Java. The solution provided by Tony M worked like a charm. I just had to adapt the calling method on Android, and it worked.

0
source

All Articles