org.restlet.client.ext.json
Class JsonRepresentation

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

public class JsonRepresentation
extends Representation

JSON representation based on an JSON value. JSON (JavaScript Object Notation) is a common serialization format similar to XML but lighter.

Author:
Jerome Louvel
See Also:
JSON

Field Summary
 
Fields inherited from class org.restlet.client.representation.Representation
UNKNOWN_SIZE
 
Constructor Summary
JsonRepresentation(MediaType mediaType)
          Constructor for an empty document.
JsonRepresentation(MediaType mediaType, JSONValue value)
          Constructor from an existing DOM document.
JsonRepresentation(Representation jsonRepresentation)
          Constructor.
JsonRepresentation(String jsonString)
          Constructor from a JSON string.
 
Method Summary
 JSONObject getJsonObject()
          Converts the representation to a JSON object.
 Reader getReader()
           
 long getSize()
           
 InputStream getStream()
           
 String getText()
           
 JSONValue getValue()
          Returns the wrapped JSON value.
 void release()
          Releases the wrapped JSON value and the source JSON representation if they have been defined.
 void setValue(JSONValue json)
          Sets the wrapped JSON value.
 
Methods inherited from class org.restlet.client.representation.Representation
createEmpty, exhaust, getAvailableSize, getDisposition, getDownloadName, getExpirationDate, getRange, isAvailable, isDownloadable, isTransient, setAvailable, setDisposition, setDownloadable, setDownloadName, setExpirationDate, setRange, setSize, setTransient
 
Methods inherited from class org.restlet.client.representation.RepresentationInfo
getModificationDate, getTag, setModificationDate, setTag
 
Methods inherited from class org.restlet.client.representation.Variant
createClientInfo, equals, getCharacterSet, getEncodings, getIdentifier, getLanguages, getLocationRef, getMediaType, includes, isCompatible, setCharacterSet, setEncodings, setIdentifier, setIdentifier, 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(MediaType mediaType)
Constructor for an empty document.

Parameters:
mediaType - The representation's media type.

JsonRepresentation

public JsonRepresentation(MediaType mediaType,
                          JSONValue value)
Constructor from an existing DOM document.

Parameters:
mediaType - The representation's media type.
value - The source JSON value.

JsonRepresentation

public JsonRepresentation(Representation jsonRepresentation)
Constructor.

Parameters:
jsonRepresentation - A source JSON representation to parse.

JsonRepresentation

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

Parameters:
jsonString - The JSON string.
Method Detail

getJsonObject

public JSONObject getJsonObject()
                         throws IOException
Converts the representation to a JSON object. This method will trigger the serialization of any wrapped JSON object.

Returns:
The converted JSON object.
Throws:
IOException

getReader

public Reader getReader()
                 throws IOException
Specified by:
getReader in class Representation
Throws:
IOException

getSize

public long getSize()
Overrides:
getSize in class Representation

getStream

public InputStream getStream()
                      throws IOException
Specified by:
getStream in class Representation
Throws:
IOException

getText

public String getText()
               throws IOException
Specified by:
getText in class Representation
Throws:
IOException

getValue

public JSONValue getValue()
                   throws IOException
Returns the wrapped JSON value. If no value is defined yet, it attempts to parse the JSON representation eventually given at construction time. Otherwise, it just creates a null JSON value.

Returns:
The wrapped DOM document.
Throws:
IOException

release

public void release()
Releases the wrapped JSON value and the source JSON representation if they have been defined.

Overrides:
release in class Representation

setValue

public void setValue(JSONValue json)
Sets the wrapped JSON value.

Parameters:
json - The wrapped JSON value.


Copyright © 2005-2010 Noelios Technologies.