Class GsonRepresentation<T>


  • public class GsonRepresentation<T>
    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:
    Neal Mi
    See Also:
    Gson project
    • Field Summary

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

        UNKNOWN_SIZE
    • Constructor Summary

      Constructors 
      Constructor Description
      GsonRepresentation​(org.restlet.representation.Representation representation, java.lang.Class<T> objectClass)
      Constructor.
      GsonRepresentation​(T object)
      Constructor for the JSON media type.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected com.google.gson.GsonBuilder createBuilder()
      Returns a new instance of the builder for Gson instances.
      com.google.gson.GsonBuilder getBuilder()
      Returns the builder for Gson instances.
      T getObject()
      Returns the wrapped object, deserializing the representation with Gson if necessary.
      java.lang.Class<T> getObjectClass()
      Returns the object class to instantiate.
      void setBuilder​(com.google.gson.GsonBuilder builder)
      Sets the Gson builder.
      void setObject​(T object)
      Sets the object to format.
      void setObjectClass​(java.lang.Class<T> objectClass)
      Sets the object class to instantiate.
      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, getSize, 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

      • GsonRepresentation

        public GsonRepresentation​(org.restlet.representation.Representation representation,
                                  java.lang.Class<T> objectClass)
        Constructor.
        Parameters:
        representation - The representation to parse.
        objectClass - The object class to instantiate.
      • GsonRepresentation

        public GsonRepresentation​(T object)
        Constructor for the JSON media type.
        Parameters:
        object - The object to format.
    • Method Detail

      • createBuilder

        protected com.google.gson.GsonBuilder createBuilder()
        Returns a new instance of the builder for Gson instances.
        Returns:
        a new instance of builder for Gson instances.
      • getBuilder

        public com.google.gson.GsonBuilder getBuilder()
        Returns the builder for Gson instances.
        Returns:
        The builder for Gson instances.
      • getObject

        public T getObject()
                    throws java.io.IOException
        Returns the wrapped object, deserializing the representation with Gson if necessary.
        Returns:
        The wrapped object.
        Throws:
        java.io.IOException
      • getObjectClass

        public java.lang.Class<T> getObjectClass()
        Returns the object class to instantiate.
        Returns:
        The object class to instantiate.
      • setBuilder

        public void setBuilder​(com.google.gson.GsonBuilder builder)
        Sets the Gson builder.
        Parameters:
        builder - The Gson builder.
      • setObject

        public void setObject​(T object)
        Sets the object to format.
        Parameters:
        object - The object to format.
      • setObjectClass

        public void setObjectClass​(java.lang.Class<T> objectClass)
        Sets the object class to instantiate.
        Parameters:
        objectClass - The object class to instantiate.
      • 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