Restlet Framework 2.2.3
Java Standard Edition

org.restlet.ext.gson
Class GsonRepresentation<T>

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.gson.GsonRepresentation<T>

public class GsonRepresentation<T>
extends 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
GsonRepresentation(Representation representation, Class<T> objectClass)
          Constructor.
GsonRepresentation(T object)
          Constructor for the JSON media type.
 
Method Summary
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.
 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(Class<T> objectClass)
          Sets the object class to instantiate.
 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, 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, 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

GsonRepresentation

public GsonRepresentation(Representation representation,
                          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 IOException
Returns the wrapped object, deserializing the representation with Gson if necessary.

Returns:
The wrapped object.
Throws:
IOException

getObjectClass

public 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(Class<T> objectClass)
Sets the object class to instantiate.

Parameters:
objectClass - The object class to instantiate.

write

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

Restlet Framework 2.2.3
Java Standard Edition

Copyright © 2005-2014 Restlet.