GWT client side Java object serialization

1,158 views
Skip to first unread message

dhoffer

unread,
Oct 18, 2012, 5:04:00 PM10/18/12
to google-we...@googlegroups.com
I have some rather complex data objects that currently get marshaled from client to server and server to client (comet communication).  Btw, not complex in quantity of data, or data relationships, but data is arrays of lots of different derived interface/class types.  The data used to be just serialized but now it needs to be sent via JSON.

Is it possible to perform regular Java object serialization in the GWT client?  If so, I could solve this by converting that binary output into Base64 encoded string and send that via the new JSON API and then just reverse that on the server.  Is it even possible to do this in GWT?

Of course the other approach is to convert the Java object into a full JSON object but given it's complexity I haven't found a way to do that yet (I posted separate newsgroup message on that approach).  Either approach would be fine for me, I can worry about performance differences later.

-Dave

Jens

unread,
Oct 18, 2012, 6:43:21 PM10/18/12
to google-we...@googlegroups.com

Is it possible to perform regular Java object serialization in the GWT client? 

Puh, once compiled your Java code is JavaScript code. No JVM available, no reflection available, classes/methods/variable names obfuscated. So your only chance would be a GWT generator that produces serialization code at compile time. This serialization code must correctly produce/consume binary data that satisfies the serialization protocol of Java: http://docs.oracle.com/javase/7/docs/platform/serialization/spec/protocol.html .

Not sure if thats possible. My feeling says no, but I also have never read up Java's serialization spec. So maybe my feeling is wrong.


Of course the other approach is to convert the Java object into a full JSON object but given it's complexity I haven't found a way to do that yet (I posted separate newsgroup message on that approach).  Either approach would be fine for me, I can worry about performance differences later.

Thats what I would try. There are 
- Json Overlay Types
- AutoBeans
- Frameworks like Piriti (http://code.google.com/p/piriti/)
- you can roll your own solution using GWT's generators at compile time.

I'll bet there should exist something that suites your needs.

-- J.
 

dhoffer

unread,
Oct 19, 2012, 4:30:14 PM10/19/12
to google-we...@googlegroups.com
I'm really having a hard time finding something that will work here.  Regarding your suggestions:

- Json Overlay Types
(This one I have not implemented yet...I was not sure how to do this)
- AutoBeans
I can't get this to work properly, there are no errors reported just doesn't work at runtime.  When using it on the server to encode I get a null bean.  When using it on the client I get what looks like a mock instance (random derived type) of the right type but it has no data.

- Frameworks like Piriti (http://code.google.com/p/piriti/)
This one almost worked...it generated code but because some of types I marshal are parameterized (pass data of type T)...it generated code that returned T but the class itself was not typed so java could not compile the code.  Seems it just does not handle parameterized types. 
I had tried this one first...ran into a problem here too...just don't recall the details.

- you can roll your own solution using GWT's generators at compile time.
(Not sure how to do this either)

Also...I found the gwt-streamer library it's purpose is to convert POJO to JSON and/or XML and the reverse.  This seemed ideal as then I could just pass the resulting string as a single item JSON map but it didn't work because the library contains code references that are not implemented in the GWT JRE emulation library.  So although it was advertised for client side GWT apps I don't see how that is possible.  

Any other suggestions?  Know of any good Json Overlay Types examples?

Thanks,
-Dave

J.Ganesan

unread,
Oct 19, 2012, 9:20:13 PM10/19/12
to google-we...@googlegroups.com
Please see www.DataStoreGwt.com. It helps you to have a single object model for driving UI and for saving. It serializes an arbitrarily complex object graph at the client side and  persists.
J.Ganesan

Honza Rames

unread,
Oct 23, 2012, 5:59:46 AM10/23/12
to google-we...@googlegroups.com
Hi, I've created a project for my own needs called GWT RTTI (http://code.google.com/p/gwt-rtti/) it generates reflection information for certain packages at compile time using generators and lets you use it on the client (it is similar to JAVA reflection API with few differences). But bare in mind that it adds additional code to your application thus making it more complex and larger. There is one advantage, I've created it in a way that it can be used on both sides client and server. It doesn't contain serialization mechanisms but you can create one on you own, if you do it carefuly you can share serialization code on the server and on the client (probably using JSONObject). If your objects are comlex POJOs in lists you should be able to create the parser pretty easily ;-).

Honza

Dne čtvrtek, 18. října 2012 23:04:00 UTC+2 dhoffer napsal(a):
Reply all
Reply to author
Forward
Message has been deleted
0 new messages