Ori Wasserman
Ori Wasserman

Reputation: 962

Google App Engine class on client side

I am developing an Android app using GAE on Eclipse.
On one of the EndPoint classes I have a method which returns a "Bla"-type object:

public Bla foo()
    {
        return new Bla();
    }

This "Bla" object holds a "Bla2"-type object:

public class Bla {
    private Bla2 bla = new Bla2();
    public Bla2 getBla() {
        return bla;
    }
    public void setBla(Bla2 bla) {
        this.bla = bla;
    }
}

Now, my problem is I cant access the "Bla2" class from the client side. (Even the method "getBla()" doesn't exist)

I managed to trick it by creating a second method on the EndPoint class which return a "Bla2" object:

public Bla2 foo2()
    {
        return new Bla2();
    }

Now I can use the "Bla2" class on the client side, but the "Bla.getBla()" method still doesn't exit. Is there a right way to do it?

Upvotes: 0

Views: 258

Answers (2)

yedidyak
yedidyak

Reputation: 1984

Try using @ApiResourceProperty on the field.

Upvotes: 0

Tom
Tom

Reputation: 17854

This isn't the 'right' way, but keep in mind that just because you are using endpoints, you don't have to stick to the endpoints way of doing things for all of your entities.

Like you, I'm using GAE/J and cloud endpoints and have an ANdroid client. It's great running Java on both the client and the server because I can share code between all my projects.

Some of my entities are communicated and shared the normal 'endpoints way', as you are doing. But for other entities I still use JSON, but just stick them in a string, send them through a generic endpoint, and deserialize them on the other side, which is easy because the entity class is in the shared code.

This allows me to send 50 different entity types through a single endpoint, and it makes it easy for me to customize the JSON serializing/deserializing for those entities.

Of course, this solution gets you in trouble if decide to add an iOS or Web (unless you use GWT) client, but maybe that isn't important to you.

(edit - added some impl. detail)

Serializing your java objects (or entities) to/from JSON is very easy, but the details depend on the JSON library you use. Endpoints can use either Jackson or GSON on the client. But for my own JSON'ing I used json.org which is built-into Android and was easy to download and add to my GAE project.

Here's a tutorial that someone just published:
http://www.survivingwithandroid.com/2013/10/android-json-tutorial-create-and-parse.html

Then I added an endpoint like this:

@ApiMethod(name = "sendData")
public void sendData( @Named("clientId") String clientId, String jsonObject )

(or something with a class that includes a List of String's so you can send multiple entities in one request.)

And put an element into your JSON which tells the server which entity the JSON should be de serialized into.

Upvotes: 1

Related Questions