[Laszlo-dev] Fwd: For Review: Change 20090905-sebastianwagner-d Summary: Migrate to Gson as JSON Marshaller, Fix Circular Reference Exception more accurate
Henry Minsky
henry.minsky at gmail.com
Sun Sep 6 11:13:39 PDT 2009
I'd like to add a section to the documentation which captures this info, for
developers
who want to maintain or improve the RPC implementation. Is there a chapter
in our
existing docs that would be appropriate for this?
---------- Forwarded message ----------
From: Sebastian Wagner <seba.wagner at gmail.com>
Date: Sat, Sep 5, 2009 at 1:53 PM
Subject: For Review: Change 20090905-sebastianwagner-d Summary: Migrate to
Gson as JSON Marshaller, Fix Circular Reference Exception more accurate
To: Henry Q Minsky <henry.minsky at gmail.com>
Cc: laszlo-reviews at openlaszlo.org
Change 20090905-sebastianwagner-d by
sebastianwagner at sebastian-wagners-macbook-pro.local on 2009-09-05 19:32:56
CEST
in
/Users/sebastianwagner/Documents/work/openlaszlo/branches/openlaszlo/trunk
for http://svn.openlaszlo.org/openlaszlo/trunk
Summary: This Fixes: LPP-8437, LPP-8029
Extends Output of RPC with Gson as marshaller. This changeset adds a new
Factory Class to set a custom Json Marshaller
LZJsonFactory => to overwrite the default Json Handling you can call the
Method: LZJsonFactory.setJsonBuilderInstance(LZBaseJsonMarshallAdapter
instance)
There are two implementations of Json:
1) The existing, that I slightly refactored to fit into the Factory +
Adapter/Interface Pattern (LZJsonMarshaller)
2) The Gson Handling which is now the default one (LZGsonMarshaller)
To write your own Marshaller you have to use the pattern
public MyMarshaller extends LZBaseJsonMarshallAdapter implements
ILZJsonMarshaller {
public synchronized byte[] createObject(Object object, String
objectReturnType) {}
}
and then set an instance of that Object with
LZJsonFactory.setJsonBuilderInstance(myMarshallerInstanceObject)
The LZGsonMarshaller has some default settings to make the JSon Output 100%
equal to the existing one.
To disable that you should call:
LZGsonMarshaller.applyLzDefaultGsonProperties = false;
To get the Gson Factory to set your custom marshalling options you have to:
GsonBuilder gsonBuilder = LZGsonMarshaller.getGsonBuilderInstance()
=> using the gsonBuilder you then can set any property that is documented
at:
http://sites.google.com/site/gson/gson-user-guide
By using Gson you can then also use annotations or other manipulations to
modify the JSon output.
See their user guide for full documentation of features.
If Gson detects a Circular Reference it will throw for example:
ava.lang.IllegalStateException: Circular reference found:
org.i4change.app.hibernate.beans.user.Users at 2855f16e
at
com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:108)
at
com.google.gson.JsonSerializationVisitor.getJsonElementForChild(JsonSerializationVisitor.java:117)
at
com.google.gson.JsonSerializationVisitor.addAsChildOfObject(JsonSerializationVisitor.java:95)
....
New Features:
Bugs Fixed: LPP-8437, Lpp-8029
Technical Reviewer: hqm
QA Reviewer: (pending)
Doc Reviewer: (pending)
Documentation:
Release Notes:
Details:
Tests:
Files:
A WEB-INF/lib/gson-1.3.jar
A
WEB-INF/lps/server/src/org/openlaszlo/remote/json/LZBaseJsonMarshallAdapter.java
A
WEB-INF/lps/server/src/org/openlaszlo/remote/json/ILZJsonMarshaller.java
A
WEB-INF/lps/server/src/org/openlaszlo/remote/json/LZGsonMarshaller.java
A WEB-INF/lps/server/src/org/openlaszlo/remote/json/LZJsonFactory.java
A
WEB-INF/lps/server/src/org/openlaszlo/remote/json/LZJsonMarshaller.java
M
WEB-INF/lps/server/src/org/openlaszlo/remote/json/LZReturnObject.java
M WEB-INF/lps/server/src/org/openlaszlo/data/JavaDataSource.java
Changeset:
http://svn.openlaszlo.org/openlaszlo/patches/20090905-sebastianwagner-d.tar
--
Sebastian Wagner
http://www.webbase-design.de
http://openmeetings.googlecode.com
http://www.laszlo-forum.de
seba.wagner at gmail.com
--
Henry Minsky
Software Architect
hminsky at laszlosystems.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.openlaszlo.org/pipermail/laszlo-dev/attachments/20090906/de88bf2c/attachment.html
More information about the Laszlo-dev
mailing list