org.omnifaces.util
Class Json

java.lang.Object
  extended by org.omnifaces.util.Json

public final class Json
extends java.lang.Object

A simple JSON encoder.

Since:
1.2
Author:
Bauke Scholtz

Method Summary
static java.lang.String encode(java.lang.Object object)
          Encodes the given object as JSON.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

encode

public static java.lang.String encode(java.lang.Object object)
Encodes the given object as JSON. This supports the standard types Boolean, Number, String and Date. It also supports Collections, Maps and arrays of them, even nested ones. The Date is formatted in RFC 1123 format, so you can if necessary just pass it straight to new Date() in JavaScript.

Complex objects like javabeans are not supported. Consider a "real" JSON library instead if you need this.

Parameters:
object - The object to be encoded as JSON.
Returns:
The JSON-encoded representation of the given object.
Throws:
java.lang.IllegalArgumentException - When an unsupported type is encountered in the given object argument.