org.japano
Class JsGenerator

java.lang.Object
  extended by org.japano.JsGenerator

public class JsGenerator
extends java.lang.Object

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


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 sendJavaScriptView(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 sendJavaScriptView(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.Object o, java.lang.String mimeType)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

sendJavaScriptView

public static void sendJavaScriptView(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.

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

sendJavaScriptView

public static void sendJavaScriptView(javax.servlet.http.HttpServletRequest request,
                                      javax.servlet.http.HttpServletResponse response,
                                      java.lang.Object o,
                                      java.lang.String mimeType)
                               throws java.io.IOException
Throws:
java.io.IOException

dumpObjectFormatted

public static java.lang.String dumpObjectFormatted(java.lang.Object o)
Dumps the given object as formatted JSON representation.

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