Class 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
    • Field Summary

      • Fields inherited from class org.restlet.representation.Representation

        UNKNOWN_SIZE
    • 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.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, hashCode, includes, isCompatible, setCharacterSet, setEncodings, setLanguages, setLocationRef, setLocationRef, setMediaType, toString
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • 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 class org.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 class org.restlet.representation.Representation
        Throws:
        java.io.IOException