-
1. Re: Android/Seam communication options
ktorp May 7, 2013 8:33 AM (in response to zzzz8)Hello.
There are probably a lot of good ways to do android - seam communication, but I can tell you how we do it, and hope this can help you and answer some of your questions.
We use gson in both ends to marshal/unmarshal json in order to make the corner cases (null handeling, double numbers with NaN or inf. and so on) behave consistently.
To make the interface more type safe and let us get some compile time errors, the json data structure and interface we use to communicate is implemented as POJOs in a shared jar file. This pojo lib is included in the android app and in the seam project and is used by gson to do all marshalling/unmarshalling. Of cause the libs need to be in sync for this to work.
In order to use gson to marshal/unmarshal the arguments and return values one the serverside, the resteasy anotated methods only have one parameter, and thats a UTF-8 string and return an UTF-8 encoded byte array. Also we only use POST in order to be able to send lots of data to the backend in a consistent way.
This is the setup that works for us on the server side:
@POST @Consumes("text/*;charset=utf-8") @Produces("text/json;charset=utf-8") @Path("/somePath") public byte[] theMethod( String parameterAsJSON) throws Exception
On the android side we use restlet to consume services.
I hope this helps.