org.restlet.ext.jackson

## Class JacksonRepresentation<T>

- java.lang.Object
- - org.restlet.representation.Variant
  - - org.restlet.representation.RepresentationInfo
    - - org.restlet.representation.Representation
      - - org.restlet.representation.CharacterRepresentation
        - - org.restlet.representation.WriterRepresentation
          - - 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

Constructors
Constructor and Description
`JacksonRepresentation(MediaType mediaType, T object)` Constructor.
`JacksonRepresentation(Representation representation, java.lang.Class<T> objectClass)` Constructor.
`JacksonRepresentation(T object)` Constructor.

### Method Summary

Methods
`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.
`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)` Writes the representation to a characters 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

`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,
                         java.lang.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()

Returns the wrapped object, deserializing the representation with Jackson if necessary.

Returns:
  The wrapped object.

#### 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

Description copied from class: `Representation`
Writes the representation to a characters writer. This method is ensured to write the full content for each invocation unless it is a transient representation, in which case an exception is thrown.
Note that the class implementing this method shouldn't flush or close the given `Writer` after writing to it as this will be handled by the Restlet connectors automatically.

Specified by:
  `write` in class `Representation`
Parameters:
  `writer` - The characters writer.
Throws:
  `java.io.IOException`