1

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?

Dan Holevoet
  • 9,183
  • 1
  • 33
  • 49
Ori Wasserman
  • 962
  • 1
  • 10
  • 24

1 Answers1

2

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;
}
Dan Holevoet
  • 9,183
  • 1
  • 33
  • 49
  • Thanks! I thought about the first solution but it looked just wrong... The second one is tricky though, can you explain to me what does this annotation means? And thanks again for the fast response. – Ori Wasserman Jan 25 '13 at 20:42
  • Arguments to an API method, by default, appear in the body (and are expected to be Java Beans). Named arguments appear in the query string (as a key/value pair), so they need a name like "d" and should be scalar types instead of Beans. – Dan Holevoet Jan 25 '13 at 20:52
  • So I understand that the string inside the annotation would be the name of the parameter the would be displayed on the client-side, and the "Double d" is the type and name just used for the method itself? – Ori Wasserman Jan 26 '13 at 00:04
  • Correct. It's treated as a normal method argument aside from the annotation. – Dan Holevoet Jan 26 '13 at 00:13