JSON <-> Objectify

939 views
Skip to first unread message

aswath satrasala

unread,
Oct 25, 2010, 10:52:11 PM10/25/10
to objectify...@googlegroups.com
Hello,
I am using GWT and Objectify.  So far, my normal process was to do the module load and do RPC to get Objectify objects as the return elements.
I read the following article
http://code.google.com/webtoolkit/articles/dynamic_host_page.html

Now, I want to send the Objectify entities in the response in JSON format.  In the OnModule load of GWT, I want to read the JSON data and convert to Objectify entities.

Any help on this.

-Aswath

Jeff Schnitzer

unread,
Oct 25, 2010, 11:24:03 PM10/25/10
to objectify...@googlegroups.com
That's a lot of work, but I'll give you a few pointers. Going from
java objects to JSON is easy - download Jackson
(http://jackson.codehaus.org/) and follow the instructions.

Going from JSON to java client side is more complicated. I'm not
aware of anything that will deserialize JSON to traditional java
objects in gwt - maybe there are parsers that can be gwt-compiled, but
you'll have to do that research. The normal way you do this is with
GWT overlay objects - it'll be much faster and more efficient than
actually parsing JSON in javascript, but it means you will have an
impedance mismatch between the java versions of your objects and the
overlay versions of your objects.

Good luck,
Jeff

aswath satrasala

unread,
Oct 25, 2010, 11:38:18 PM10/25/10
to objectify...@googlegroups.com
I have few helper routines for what I wanted to do.  However, I have issue with converting JSON to Objectify keys.

-Aswath

Jeff Schnitzer

unread,
Oct 26, 2010, 12:54:00 AM10/26/10
to objectify...@googlegroups.com
Make the key objects convert to string form and back - it'll be easier
than dealing with the recursive structure of a key.

Jeff

On Mon, Oct 25, 2010 at 8:38 PM, aswath satrasala

aswath satrasala

unread,
Oct 26, 2010, 1:33:55 AM10/26/10
to objectify...@googlegroups.com
Two issues:
  • I can do Key<>.toString() on the server end.  This function outputs lots of '{', '}' characters which might interfere with the JSON format.
  •  How do I reconstruct on the GWT.
Any more pointers...

-Aswath

Jeff Schnitzer

unread,
Oct 26, 2010, 1:47:18 AM10/26/10
to objectify...@googlegroups.com
On Mon, Oct 25, 2010 at 10:33 PM, aswath satrasala
<aswath.s...@gmail.com> wrote:
> Two issues:
>
> I can do Key<>.toString() on the server end.  This function outputs lots of
> '{', '}' characters which might interfere with the JSON format.

Are you generating JSON by hand? Don't. Use a serializer like
Jackson that does proper escaping.

>  How do I reconstruct on the GWT.

I wouldn't try - in the past I've used gwt overlays for this kind of
thing. If you're dedicated to parsing JSON in javascript, here's
where I would start: http://lmgtfy.com/?q=gwt+json+parser

Jeff

Martin Algesten

unread,
Oct 26, 2010, 2:19:13 AM10/26/10
to objectify...@googlegroups.com

I've toyed with the idea of extending the google RPC mechanism to use JSON as transport. Doable, but a bit involved.

http://timepedia.blogspot.com/2009/04/gwt-rpc-over-arbitrary-transports-uber.html

M

Harald Pehl

unread,
Oct 27, 2010, 3:17:59 AM10/27/10
to objectify-appengine
Feel free to take a look at Piriti (http://code.google.com/p/piriti/).
It's a JSON / XML mapper for GWT based on annotations and deferred
binding. There's no dedicated support for Objectify / Keys, but it
supports inheritance and relations between POJOs.

- Harald

On Oct 26, 8:19 am, Martin Algesten <mar...@algesten.se> wrote:
> I've toyed with the idea of extending the google RPC mechanism to use JSON as transport. Doable, but a bit involved.
>
> http://timepedia.blogspot.com/2009/04/gwt-rpc-over-arbitrary-transpor...

aswath satrasala

unread,
Oct 28, 2010, 5:42:52 AM10/28/10
to objectify...@googlegroups.com
I also happened to see this http://code.google.com/p/piriti/ and also was on my radar to read more on this.  I am wondering, if the keys can be constructed back on the GWT.

-Aswath

David Chandler

unread,
Oct 29, 2010, 1:25:47 PM10/29/10
to objectify-appengine
Aswath,

The GWT 2.1 RequestFactory (http://code.google.com/webtoolkit/doc/
latest/DevGuideRequestFactory.html) uses JSON under the covers,
although the wire protocol is deliberately not exposed because it may
change. Serialization of Keys is not an issue since RF uses DTO
interfaces on the client. It does not yet support @Embedded objects or
DAOs; however, I have it on good authority that these are planned for
GWT 2.1.1, and compatibility with all the major App Engine persistence
layers (including Objectify) is on the GWT team's radar.

/dmc
http://turbomanage.wordpress.com

On Oct 28, 5:42 am, aswath satrasala <aswath.satras...@gmail.com>
wrote:
> I also happened to see thishttp://code.google.com/p/piriti/and also was on
> my radar to read more on this.  I am wondering, if the keys can be
> constructed back on the GWT.
>
> -Aswath
>

David Keyes

unread,
Apr 11, 2012, 1:52:26 AM4/11/12
to objectify...@googlegroups.com, aswath.s...@gmail.com
I've gotten the serialization of Objectify objects using Jackon (via Restlet) to work for me in my GAE apps.  You can see the details here: http://keyeslabs.com/joomla/blogs/i-think-im-becoming-an-android/431-serializing-objectify-keys-with-restletjacksongwt.  Hope this helps...

Huseyn Guliyev

unread,
Apr 15, 2012, 9:54:41 AM4/15/12
to objectify...@googlegroups.com, aswath.s...@gmail.com
As for Jackson and Objectify, there a jackson module for objectify
which according to its description:
Add-on module for Jackson (http://jackson.codehaus.org) to support Objectify (http://code.google.com/p/objectify-appengine/) specific datatypes 

Works like a charm for us.
Hope this helps.

Jeff Schnitzer

unread,
Apr 15, 2012, 11:31:34 AM4/15/12
to objectify...@googlegroups.com
Funny, I was just thinking about folding my jackson (2.0) serializers
into the main jar. Like the joda translators, this only creates a
run-time dependency if you actually use them. I also have
deserializers and (map-)key serializers. Also serializers for
BlobKey.

I didn't think to make the Ref serializer switch between rendering the
key string or object depending on load state. That's a brilliant
idea. I will use this.

It's a trivial amount of code and might as well go into objectify.jar.

Jeff

Tristan Burch

unread,
Apr 15, 2012, 12:23:16 PM4/15/12
to objectify...@googlegroups.com
It'd be great to have these be part of Objectify and then just be a runtime dependency if you're using them. I haven't looked into what needs to be changed with my jackson-module-objectify project for jackson 2.0.

-Tristan

Jeff Schnitzer

unread,
Apr 15, 2012, 2:04:28 PM4/15/12
to objectify...@googlegroups.com
It's checked in. Look at
com.googlecode.objectify.util.jackson.ObjectifyJacksonModule as a
starting point.

The transition to Jackson 2.0 is pretty easy - for the most part, just
the package changed. Tatu finally got rid of the zillions of
deprecated methods so you might find a few more changes... but overall
the interface is actually simpler and easier to understand now. All
those redundant config methods were painful.

Jeff

Reply all
Reply to author
Forward
0 new messages