Package org.restlet.ext.json
Class JsonRepresentation
- java.lang.Object
-
- org.restlet.representation.Variant
-
- org.restlet.representation.RepresentationInfo
-
- org.restlet.representation.Representation
-
- org.restlet.representation.CharacterRepresentation
-
- org.restlet.representation.WriterRepresentation
-
- org.restlet.ext.json.JsonRepresentation
-
public class JsonRepresentation extends org.restlet.representation.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
-
-
Constructor Summary
Constructors Constructor Description JsonRepresentation(java.lang.Object bean)
Constructor from a bean using reflection to generate JSON names.JsonRepresentation(java.lang.String jsonString)
Constructor from a JSON string.JsonRepresentation(java.util.Map<java.lang.String,java.lang.Object> map)
Constructor from a map object.JsonRepresentation(org.json.JSONArray jsonArray)
Constructor from a JSON array.JsonRepresentation(org.json.JSONObject jsonObject)
Constructor from a JSON object.JsonRepresentation(org.json.JSONStringer jsonStringer)
Constructor from a JSON stringer.JsonRepresentation(org.json.JSONTokener jsonTokener)
Constructor from a JSON tokener.JsonRepresentation(org.restlet.representation.Representation jsonRepresentation)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getIndentingSize()
Returns the number of spaces to use for indentation.org.json.JSONArray
getJsonArray()
Gets the wrapped JSON array or converts the wrapped representation if needed.org.json.JSONObject
getJsonObject()
Gets the wrapped JSON object or converts the wrapped representation if needed.org.json.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.void
write(java.io.Writer writer)
-
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
-
-
-
-
Constructor Detail
-
JsonRepresentation
public JsonRepresentation(org.json.JSONArray jsonArray)
Constructor from a JSON array.- Parameters:
jsonArray
- The JSON array.
-
JsonRepresentation
public JsonRepresentation(org.json.JSONObject jsonObject)
Constructor from a JSON object.- Parameters:
jsonObject
- The JSON object.
-
JsonRepresentation
public JsonRepresentation(org.json.JSONStringer jsonStringer)
Constructor from a JSON stringer.- Parameters:
jsonStringer
- The JSON stringer.
-
JsonRepresentation
public JsonRepresentation(org.json.JSONTokener jsonTokener)
Constructor from a JSON tokener.- Parameters:
jsonTokener
- The JSON tokener.
-
JsonRepresentation
public JsonRepresentation(java.util.Map<java.lang.String,java.lang.Object> map)
Constructor from a map object.- Parameters:
map
- The map to convert to JSON.- See Also:
JSONObject(Map)
-
JsonRepresentation
public JsonRepresentation(java.lang.Object bean)
Constructor from a bean using reflection to generate JSON names.- Parameters:
bean
- The bean to convert to JSON.- See Also:
JSONObject(Object)
-
JsonRepresentation
public JsonRepresentation(org.restlet.representation.Representation jsonRepresentation)
Constructor.- Parameters:
jsonRepresentation
- A source JSON representation to parse.
-
JsonRepresentation
public JsonRepresentation(java.lang.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 org.json.JSONArray getJsonArray() throws org.json.JSONException
Gets the wrapped JSON array or converts the wrapped representation if needed.- Returns:
- The converted JSON array.
- Throws:
org.json.JSONException
-
getJsonObject
public org.json.JSONObject getJsonObject() throws org.json.JSONException
Gets the wrapped JSON object or converts the wrapped representation if needed.- Returns:
- The converted JSON object.
- Throws:
org.json.JSONException
-
getJsonTokener
public org.json.JSONTokener getJsonTokener() throws org.json.JSONException
Gets the wrapped JSON tokener or converts the wrapped representation if needed.- Returns:
- The converted JSON tokener.
- Throws:
org.json.JSONException
-
getSize
public long getSize()
- Overrides:
getSize
in classorg.restlet.representation.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.
-
write
public void write(java.io.Writer writer) throws java.io.IOException
- Specified by:
write
in classorg.restlet.representation.Representation
- Throws:
java.io.IOException
-
-