Question

So far I was able to find all answers to my questions in Google, but this time I gave up and created an account...

I started using GAE for Android application in Eclipse, and I'm writing an API, with, of course, ApiMethods.
One of the methods I wrote has a return value, but in the client code it seems to be void.
This is the extremely useful method I'm trying to generate:

@ApiMethod(name = "weather.bla")
public double Bla(double d)
{
    return 2.5;
}

As you can see, this method gets a double variable as a parameter and returns a double, but on the client-side code, it doesn't seem to acknowledge those doubles.(It auto-completes to weather().bla() and the .execute() method is Void)
I even tried to edit the generated code and add the doubles in the necessary places, but than when I tried to run the application it sort of exploded, no "force close" alert, no warning, the app just vanished.

The even weirder thing is, that I have a class on the GAE code called "Weather", and ApiMethods which uses the Weather class gets generated perfectly.

Am I missing some basic stuff in here?

Was it helpful?

Solution

You should be passing around Java Beans as your argument and return types. This will work:

class Response {
  private Double d;

  // getter and setter
}

@ApiMethod(name = "weather.bla")
public Response Bla()
{
  Response r = new Response();
  r.setD(2.5)
  return r;
}

The exception to this is query parameters (as arguments to an API method). If annotate an argument with the @Named annotation, it no longer needs to be a Java Bean (you can use Double, String, Long, etc.) For example:

@ApiMethod(name = "weather.bla")
public Response Bla(@Named("d") Double d)
{
  Response r = new Response();
  r.setD(d)
  return r;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top