org.restlet.ext.jackson
Class JacksonRepresentation<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.jackson.JacksonRepresentation<T>
Type Parameters:
T - The type to wrap.

public class JacksonRepresentation<T>
extends WriterRepresentation

Representation based on the Jackson library. It can serialize and deserialize automatically in JSON.

Author:
Jerome Louvel
See Also:
Jackson project

Field Summary
 
Fields inherited from class org.restlet.representation.Representation
UNKNOWN_SIZE
 
Constructor Summary
JacksonRepresentation(MediaType mediaType, T object)
          Constructor.
JacksonRepresentation(Representation representation, Class<T> objectClass)
          Constructor.
JacksonRepresentation(T object)
          Constructor.
 
Method Summary
protected  org.codehaus.jackson.map.ObjectMapper createObjectMapper()
          Creates a Jackson object mapper based on a media type.
 T getObject()
          Returns the wrapped object, deserializing the representation with Jackson if necessary.
 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(Class<T> objectClass)
          Sets the object class to instantiate.
 void setObjectMapper(org.codehaus.jackson.map.ObjectMapper objectMapper)
          Sets the Jackson object mapper.
 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

JacksonRepresentation

public JacksonRepresentation(MediaType mediaType,
                             T object)
Constructor.

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

JacksonRepresentation

public JacksonRepresentation(Representation representation,
                             Class<T> objectClass)
Constructor.

Parameters:
representation - The representation to parse.

JacksonRepresentation

public JacksonRepresentation(T object)
Constructor.

Parameters:
object - The object to format.
Method Detail

createObjectMapper

protected org.codehaus.jackson.map.ObjectMapper createObjectMapper()
Creates a Jackson object mapper based on a media type. By default, it calls ObjectMapper.ObjectMapper(JsonFactory).

Returns:
The Jackson object mapper.

getObject

public T getObject()
            throws IOException
Returns the wrapped object, deserializing the representation with Jackson 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.

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(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(Writer writer)
           throws IOException
Specified by:
write in class Representation
Throws:
IOException


Copyright © 2005-2013 Restlet.