Open GoogleCodeExporter opened 9 years ago
[deleted comment]
The code generation service is independent of GPE, but it looks like you're
trying to recreate the functionality of the endpoints framework on your own.
As long as you're within the GCM data limit (4k?), you should be able to reuse
the class (DataParcel) on the AppEngine side and Android side. If you're
asking what serialization method you should use, that is up to you. You DONT
have to use any of the http response stuff. Just regular JSON serialization
and de-serialization should work.
Original comment by a...@google.com
on 19 Jun 2013 at 6:45
"The code generation service is independent of GPE..."
Yes, but I couldn't find a better place to add this issue.
The AppEngine side is not a problem - I can add any code I want to the server
version of DataParcel.
On Android, the generated version is annotated for Google Client Library JSON.
At first glance I was not able to find a way to use that libraries' JSON
functionality independent of HTTP request response, but perhaps I missed
something.
In any event, I have written regular JSON code for my DataParcel class, as you
suggest. That code would be much more elegant if I could inherit from
DataParcel, and the issue will become more important when I have 10 or 100 such
classes that need JSON and other code (my validity test and debug print
functions for starters).
So, if there is a reason that the generated code must be final and private then
that is fine, but if there isn't, then I think it would be helpful if that
could be changed.
Original comment by t...@malcolmson.ca
on 19 Jun 2013 at 7:02
Okay, so I was playing around with this a little and maybe I don't completely
understand your issue... but I think I may have a solution for what I think it
is.
To use the Google GsonFactory (toString an fromString) functionality you need
to annotate your class (just the fields) on the App Engine Side with the same
annotations you see on the generated client libraries side. Those annotations
actually decide what fields are going to be serialized and how, if they are
missing the field is ignored by the GsonFactory functions. (I've only tried
this in a simple example, I'm not sure if/how it would it affect your
persistence)
I'm not sure how much code you added to do the JSON stuff, but with GsonFactory
the extra code is very small.
Original comment by a...@google.com
on 19 Jun 2013 at 8:20
I appreciate your continued effort to help me out, but I'm not sure I follow.
The Java classes generated by endpoints have annotations like this:
@com.google.api.client.util.Key
private java.lang.String typeId;
I can copy those annotations to my server side code, but I think those
annotations will only work with the Google Client Library. (I think GSON uses
@Expose?)
Actually, adding JSON serializing on the server side wasn't a problem - I have
full control of my class on the server.
Where I had to get hacky was on the client side - due to the lack of
flexibility and control that the developer has over the generated code. I
think I've seen other devs comment on that too - that they hoped for more
@ApiMethod type annotations to allow them great control over the generated
client side code.
Original comment by t...@malcolmson.ca
on 19 Jun 2013 at 8:38
Yeah I guess I should have mentioned you need some of the client library jars
added to your App Engine project. So you could do that if you like, but I see
what you're saying.
The code gen guys said you should file your bug against "final" in this list :
https://code.google.com/p/google-api-java-client/issues/list
Original comment by a...@google.com
on 19 Jun 2013 at 9:17
Okay, I added it as:
https://code.google.com/p/google-api-java-client/issues/detail?id=802
Original comment by t...@malcolmson.ca
on 19 Jun 2013 at 9:46
I have tried the GsonFactory solution, but I have the feeling that the
endpoints are not using the GsonFactory at all. I had to add some maven
dependencies to get the GsonFactory into my project.
So, is it not possible to use the same json classes that the endpoints are
using? Because that would mean I have exactly the same as the endpoint and
don't need extra annotations.
Original comment by Peter.Fortuin
on 28 Apr 2014 at 9:03
Original issue reported on code.google.com by
t...@malcolmson.ca
on 19 Jun 2013 at 5:17