fr.cnes.sitools.common
Class SitoolsJacksonRepresentation<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 fr.cnes.sitools.common.SitoolsJacksonRepresentation<T>
Type Parameters:
T - The type to wrap.

public final class SitoolsJacksonRepresentation<T>
extends org.restlet.representation.WriterRepresentation

Representation based on the JACKSON library. It can serialize and unserialize automatically to JSON.

Author:
Jerome Louvel
See Also:
Jackson project

Field Summary
 
Fields inherited from class org.restlet.representation.Representation
UNKNOWN_SIZE
 
Constructor Summary
SitoolsJacksonRepresentation(org.restlet.data.MediaType mediaType, T object)
          Constructor.
SitoolsJacksonRepresentation(org.restlet.representation.Representation representation, java.lang.Class<T> objectClass)
          Constructor.
SitoolsJacksonRepresentation(T object)
          Constructor.
 
Method Summary
 java.lang.String convertStreamToString(java.io.InputStream is)
          Converts a stream into a simple string
 T getObject()
          Returns the wrapped object, deserializing the representation with Jackson if necessary.
 T getObject(java.lang.String rootNode)
          Get the object
 java.lang.Class<T> getObjectClass()
          Returns the object class to instantiate.
 org.codehaus.jackson.map.ObjectMapper getObjectMapper()
          Returns the modifiable Jackson object mapper.
 void setObject(T object)
          Sets the object to format.
 void setObjectClass(java.lang.Class<T> objectClass)
          Sets the object class to instantiate.
 void setObjectMapper(org.codehaus.jackson.map.ObjectMapper objectMapper)
          Sets the Jackson object mapper.
 void write(java.io.Writer writer)
           
 
Methods inherited from class org.restlet.representation.WriterRepresentation
getReader, release, write
 
Methods inherited from class org.restlet.representation.CharacterRepresentation
getChannel, getStream, write
 
Methods inherited from class org.restlet.representation.Representation
checkDigest, checkDigest, computeDigest, createEmpty, exhaust, getAvailableSize, getDigest, getDisposition, getDownloadName, getExpirationDate, getRange, getSize, getText, isAvailable, isDownloadable, isTransient, setAvailable, setDigest, setDisposition, setDownloadable, setDownloadName, setExpirationDate, 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, getIdentifier, getLanguages, getLocationRef, getMediaType, includes, isCompatible, setCharacterSet, setEncodings, setIdentifier, setIdentifier, setLanguages, setLocationRef, setLocationRef, setMediaType, toString
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SitoolsJacksonRepresentation

public SitoolsJacksonRepresentation(org.restlet.data.MediaType mediaType,
                                    T object)
Constructor.

Parameters:
mediaType - The target media type.
object - The object to format.

SitoolsJacksonRepresentation

public SitoolsJacksonRepresentation(org.restlet.representation.Representation representation,
                                    java.lang.Class<T> objectClass)
Constructor.

Parameters:
representation - The representation to parse.
objectClass - class of the object to parse

SitoolsJacksonRepresentation

public SitoolsJacksonRepresentation(T object)
Constructor.

Parameters:
object - The object to format.
Method Detail

getObject

public T getObject()
Returns the wrapped object, deserializing the representation with Jackson if necessary.

Returns:
The wrapped object.

getObject

public T getObject(java.lang.String rootNode)
Get the object

Parameters:
rootNode - the node where you have root
Returns:
an object of type T

getObjectClass

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

Returns:
The object class to instantiate.

getObjectMapper

public org.codehaus.jackson.map.ObjectMapper getObjectMapper()
Returns the modifiable Jackson object mapper. Useful to customize mappings.

Returns:
The modifiable Jackson object mapper.

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.

setObjectMapper

public void setObjectMapper(org.codehaus.jackson.map.ObjectMapper objectMapper)
Sets the Jackson object mapper.

Parameters:
objectMapper - The Jackson object mapper.

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

convertStreamToString

public java.lang.String convertStreamToString(java.io.InputStream is)
                                       throws java.io.IOException
Converts a stream into a simple string

Parameters:
is - the input stream
Returns:
a string representing the stream
Throws:
java.io.IOException - when a problem occurs in reading the stream


Copyright © 2010-2013 CNES. All Rights Reserved.