[xwiki-devs] JSON Velocity Tool (Reloaded)
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
Excuse me for the question just before the vote. Does this include a way to output json in a streamed fashion? E.g. from a Lucene search result? If yes, this should be documented. If not, is this hard to impossible? (is the String output really the only possible output of velocity? that sounds bad to me). I guess that if this remains no, one will still see people output a part of their json in velocity text and a part using that tool which is not the best practice to my taste. paul Le 14 mars 2012 à 09:08, Marius Dumitru Florea a écrit :
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
+1 On Wed, Mar 14, 2012 at 9:08 AM, Marius Dumitru Florea <[email protected]> wrote:
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
-- Thomas Mortagne
+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 .
Hi. Can't you add a parser function too ? Right now, we have to use groovy for JSON parsing. It would be better to have it in velocity directly, don't you think ? 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
+1 On Wed, Mar 14, 2012 at 11:26, Guillaume Delhumeau <[email protected]>wrote:
Hi.
Can't you add a parser function too ?
Right now, we have to use groovy for JSON parsing. It would be better to have it in velocity directly, don't you think ?
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
-- Denis Gervalle SOFTEC sa - CEO eGuilde sarl - CTO
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
participants (6)
-
Andreas Jonsson -
Denis Gervalle -
Guillaume Delhumeau -
Marius Dumitru Florea -
Paul Libbrecht -
Thomas Mortagne