org.japano.util
Class JSON

java.lang.Object
  extended by org.japano.util.JSON

public class JSON
extends java.lang.Object

Tool class with only static methods used to construct JSON representations of nested java object graphs. The object graphs can contain the following components:

Version:
$Id: JSON.java,v 1.1 2005/12/30 15:54:02 fforw Exp $ SourceForge.net Logo
Author:
Sven Helmberger ( sven dot helmberger at gmx dot de )

Method Summary
static void dumpObject(Buffer out, java.lang.Object o)
          Dumps the given object as JSON representation into the given buffer
static java.lang.String dumpObjectFormatted(java.lang.Object o)
          Dumps the given object as formatted JSON representation.
static java.lang.String forValue(java.lang.Object o)
          Returns a JSON representation of the given object as String.
static java.lang.String forValue(java.lang.Object o, boolean formatted)
          Returns a JSON representation of the given object as String.
static void send(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.Object o)
          Answers the given request with the given object in JSON representation.
static void send(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.Object o, java.lang.String mimeType)
          Answers the given request with the given object in JSON representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

send

public static void send(javax.servlet.http.HttpServletRequest request,
                        javax.servlet.http.HttpServletResponse response,
                        java.lang.Object o)
                 throws java.io.IOException
Answers the given request with the given object in JSON representation. This method uses the mime-type "text/html". This is the default mime type because of character set problems when using "text/javascript" in Opera.

Parameters:
request - Request
response - Response
o - Object
Throws:
java.io.IOException - if the response can't be send.

send

public static void send(javax.servlet.http.HttpServletRequest request,
                        javax.servlet.http.HttpServletResponse response,
                        java.lang.Object o,
                        java.lang.String mimeType)
                 throws java.io.IOException
Answers the given request with the given object in JSON representation.

Parameters:
request - Request
response - Response
o - Object
mimeType - mime type to use
Throws:
java.io.IOException - if the response can't be send.

dumpObjectFormatted

public static java.lang.String dumpObjectFormatted(java.lang.Object o)
Dumps the given object as formatted JSON representation. The method dumps the object to JSON first and reformats it then, so it's not the fastest method. It is mainly thought to provide debug output or similar.

Parameters:
o - Object
Returns:
JSON representation

dumpObject

public static void dumpObject(Buffer out,
                              java.lang.Object o)
Dumps the given object as JSON representation into the given buffer

Parameters:
out - buffer
o - object

forValue

public static java.lang.String forValue(java.lang.Object o)
Returns a JSON representation of the given object as String.

Parameters:
o - object
Returns:
JSON representation

forValue

public static java.lang.String forValue(java.lang.Object o,
                                        boolean formatted)
Returns a JSON representation of the given object as String.

Parameters:
o - object
formatted - if true, the JSON object will be split in mulitple lines and indented.
Returns:
JSON representation