Re: [xwiki-devs] JSON Velocity Tool (Reloaded)
On Fri, May 4, 2012 at 1:32 PM, Paul Libbrecht <[email protected]> wrote:
Hello Marius,
What has been the final decision here? I'm about to need an upgrade to JSON-lib used in Curriki because that library doesn't stream the json objects out... so I'd better use the same library. Was Jackson used? JSON.simple? In the xwiki-4.0 download, I only see json-lib 2.4.
As you can see from https://github.com/xwiki/xwiki-commons/commit/ac22d47d0f826c93b019d9a7f6fe1e... I've used json-lib in the end but the JSONTool API (method signatures) is not bound to any JSON implementation so we could change the JSON library later. Hope this helps, Marius
thanks in advance
Paul
Le 14 mars 2012 à 13:14, Marius Dumitru Florea a écrit :
On Wed, Mar 14, 2012 at 12:26 PM, Guillaume Delhumeau <[email protected]> wrote:
Hi.
Can't you add a parser function too ?
A parser function needs to return an object:
* either the JSON object from some JSON library, but that means binding the Velocity tool to a specific JSON library and I tried to avoid this for the moment until we reach an agreement regarding the JSON library to use * a wrapper for the JSON object from some JSON library to hide the JSON implementation, but that's a lot of work and I don't have time for it right now * a Java object, but for this you need a JSON-Java mapping, which is specific to the JSON library used and it requires some work to make a generic binding method
Right now, we have to use groovy for JSON parsing. It would be better to have it in velocity directly, don't you think ?
Yes, but I don't have time for it right now.
Thanks, Marius
Thanks,
Guillaume
2012/3/14 Andreas Jonsson <[email protected]>
+1
2012-03-14 09:08, Marius Dumitru Florea skrev:
Hi devs,
Following the discussion on http://lists.xwiki.org/pipermail/devs/2012-March/049889.html I'd like to add a JSON Velocity tool that has (for now) just one method:
/** * Serialize a Java object to the JSON format. * <p> * Examples: * <ul> * <li>numbers and boolean values: 23, 13.5, true, false</li> * <li>strings: "one\"two'three" (quotes included)</li> * <li>arrays and collections: [1, 2, 3]</li> * <li>maps: {"number": 23, "boolean": false, "string": "value"}</li> * <li>beans: {"enabled": true, "name": "XWiki"} for a bean that has #isEnabled() and #getName() getters</li> * </ul> * * @param object the object to be serialized to the JSON format * @return the JSON-verified string representation of the given object */ public String serialize(Object object)
This method is able to do what both of the initially proposed methods were able and it doesn't expose the JSON library used (so that we can change it later if we want). I'll use json-lib for the initial implementation and we can move to Jackson or other JSON library later.
WDYT? I'd like to commit this ASAP.
Thanks, Marius _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs .
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
participants (1)
-
Marius Dumitru Florea