org.xwiki.velocity.tools
Class JSONTool

java.lang.Object
  extended by org.xwiki.velocity.tools.JSONTool

public class JSONTool
extends Object

Velocity tool to facilitate serialization of Java objects to the JSON format.

Since:
4.0M2
Version:
$Id: e2f6667a9f67642196b03993b4aa325c218471ab $

Constructor Summary
JSONTool()
           
 
Method Summary
 net.sf.json.JSON parse(String json)
          Parse a serialized JSON into a real JSON object.
 String serialize(Object object)
          Serialize a Java object to the JSON format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSONTool

public JSONTool()
Method Detail

serialize

public String serialize(Object object)
Serialize a Java object to the JSON format.

Examples:

Parameters:
object - the object to be serialized to the JSON format
Returns:
the JSON-verified string representation of the given object

parse

public net.sf.json.JSON parse(String json)
Parse a serialized JSON into a real JSON object. Only valid JSON strings can be parsed, and doesn't support JSONP. If the argument is not valid JSON, then null is returned.

Parameters:
json - the string to parse, must be valid JSON
Returns:
the parsed JSON, either a JSONObject or a JSONArray, or null if the argument is not a valid JSON
Since:
5.2M1


Copyright © 2004–2014 XWiki. All rights reserved.