org.restlet.ext.json
Class JsonRepresentation

java.lang.Object
  extended by org.restlet.representation.Variant
      extended by org.restlet.representation.RepresentationInfo
          extended by org.restlet.representation.Representation
              extended by org.restlet.representation.CharacterRepresentation
                  extended by org.restlet.representation.WriterRepresentation
                      extended by org.restlet.ext.json.JsonRepresentation

public class JsonRepresentation
extends WriterRepresentation

Representation based on a JSON document. JSON stands for JavaScript Object Notation and is a lightweight data-interchange format.

Author:
Jerome Louvel
See Also:
JSON home

Field Summary
 
Fields inherited from class org.restlet.representation.Representation
UNKNOWN_SIZE
 
Constructor Summary
JsonRepresentation(JSONArray jsonArray)
          Constructor from a JSON array.
JsonRepresentation(JSONObject jsonObject)
          Constructor from a JSON object.
JsonRepresentation(JSONStringer jsonStringer)
          Constructor from a JSON stringer.
JsonRepresentation(JSONTokener jsonTokener)
          Constructor from a JSON tokener.
JsonRepresentation(Map<String,Object> map)
          Constructor from a map object.
JsonRepresentation(Object bean)
          Constructor from a bean using reflection to generate JSON names.
JsonRepresentation(Representation jsonRepresentation)
          Constructor.
JsonRepresentation(String jsonString)
          Constructor from a JSON string.
 
Method Summary
 int getIndentingSize()
          Returns the number of spaces to use for indentation.
 JSONArray getJsonArray()
          Gets the wrapped JSON array or converts the wrapped representation if needed.
 JSONObject getJsonObject()
          Gets the wrapped JSON object or converts the wrapped representation if needed.
 JSONTokener getJsonTokener()
          Gets the wrapped JSON tokener or converts the wrapped representation if needed.
 long getSize()
           
 boolean isIndenting()
          Indicates if JSON objects and arrays should be indented.
 void setIndenting(boolean indenting)
          Indicates if JSON objects and arrays should be indented.
 void setIndentingSize(int indentFactor)
          Sets the number of spaces to use for indentation.
 JSONTokener toJsonTokener()
          Deprecated. Use getJsonTokener() instead.
 void write(Writer writer)
           
 
Methods inherited from class org.restlet.representation.WriterRepresentation
getReader
 
Methods inherited from class org.restlet.representation.CharacterRepresentation
getChannel, getStream, write, write
 
Methods inherited from class org.restlet.representation.Representation
append, exhaust, getAvailableSize, getDigest, getDisposition, getExpirationDate, getRange, getRegistration, getText, hasKnownSize, isAvailable, isEmpty, isSelectable, isTransient, release, setAvailable, setDigest, setDisposition, setExpirationDate, setListener, setRange, setSize, setTransient
 
Methods inherited from class org.restlet.representation.RepresentationInfo
getModificationDate, getTag, setModificationDate, setTag
 
Methods inherited from class org.restlet.representation.Variant
createClientInfo, equals, getCharacterSet, getEncodings, getLanguages, getLocationRef, getMediaType, includes, isCompatible, setCharacterSet, setEncodings, setLanguages, setLocationRef, setLocationRef, setMediaType, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JsonRepresentation

public JsonRepresentation(JSONArray jsonArray)
Constructor from a JSON array.

Parameters:
jsonArray - The JSON array.

JsonRepresentation

public JsonRepresentation(JSONObject jsonObject)
Constructor from a JSON object.

Parameters:
jsonObject - The JSON object.

JsonRepresentation

public JsonRepresentation(JSONStringer jsonStringer)
Constructor from a JSON stringer.

Parameters:
jsonStringer - The JSON stringer.

JsonRepresentation

public JsonRepresentation(JSONTokener jsonTokener)
Constructor from a JSON tokener.

Parameters:
jsonTokener - The JSON tokener.

JsonRepresentation

public JsonRepresentation(Map<String,Object> map)
Constructor from a map object.

Parameters:
map - The map to convert to JSON.
See Also:
JSONObject.JSONObject(Map)

JsonRepresentation

public JsonRepresentation(Object bean)
Constructor from a bean using reflection to generate JSON names.

Parameters:
bean - The bean to convert to JSON.
See Also:
JSONObject.JSONObject(Object)

JsonRepresentation

public JsonRepresentation(Representation jsonRepresentation)
                   throws IOException
Constructor.

Parameters:
jsonRepresentation - A source JSON representation to parse.
Throws:
IOException

JsonRepresentation

public JsonRepresentation(String jsonString)
Constructor from a JSON string.

Parameters:
jsonString - The JSON string.
Method Detail

getIndentingSize

public int getIndentingSize()
Returns the number of spaces to use for indentation.

Returns:
The number of spaces to use for indentation.

getJsonArray

public JSONArray getJsonArray()
                       throws JSONException
Gets the wrapped JSON array or converts the wrapped representation if needed.

Returns:
The converted JSON array.
Throws:
JSONException

getJsonObject

public JSONObject getJsonObject()
                         throws JSONException
Gets the wrapped JSON object or converts the wrapped representation if needed.

Returns:
The converted JSON object.
Throws:
JSONException

getJsonTokener

public JSONTokener getJsonTokener()
                           throws JSONException
Gets the wrapped JSON tokener or converts the wrapped representation if needed.

Returns:
The converted JSON tokener.
Throws:
JSONException

getSize

public long getSize()
Overrides:
getSize in class Representation

isIndenting

public boolean isIndenting()
Indicates if JSON objects and arrays should be indented.

Returns:
True if JSON objects and arrays should be indented.

setIndenting

public void setIndenting(boolean indenting)
Indicates if JSON objects and arrays should be indented.

Parameters:
indenting - True if JSON objects and arrays should be indented.

setIndentingSize

public void setIndentingSize(int indentFactor)
Sets the number of spaces to use for indentation.

Parameters:
indentFactor - The number of spaces to use for indentation.

toJsonTokener

@Deprecated
public JSONTokener toJsonTokener()
                          throws JSONException
Deprecated. Use getJsonTokener() instead.

Converts the representation to a JSON tokener. This method will trigger the serialization of any wrapped JSON tokener.

Returns:
The converted JSON tokener.
Throws:
JSONException

write

public void write(Writer writer)
           throws IOException
Specified by:
write in class Representation
Throws:
IOException


Copyright © 2005-2014 Restlet.