org.restlet.ext.jackson

## Class JacksonConverter

- java.lang.Object
- - org.restlet.engine.Helper
  - - org.restlet.engine.converter.ConverterHelper
    - - org.restlet.ext.jackson.JacksonConverter

    public class JacksonConverter
    extends ConverterHelper

Converter between the JSON and Representation classes based on Jackson.

Author:
  Jerome Louvel

### Constructor Summary

Constructors
Constructor and Description
`JacksonConverter()`

### Method Summary

Methods
`protected <T> JacksonRepresentation<T>` `create(MediaType mediaType, T source)` Creates the marshaling `JacksonRepresentation`.
`protected <T> JacksonRepresentation<T>` `create(Representation source, java.lang.Class<T> objectClass)` Creates the unmarshaling `JacksonRepresentation`.
`protected org.codehaus.jackson.map.ObjectMapper` `createObjectMapper()` Creates a Jackson object mapper based on a media type.
`java.util.List<java.lang.Class<?>>` `getObjectClasses(Variant source)` Returns the list of object classes that can be converted from a given variant.
`org.codehaus.jackson.map.ObjectMapper` `getObjectMapper()` Returns the modifiable Jackson object mapper.
`java.util.List<VariantInfo>` `getVariants(java.lang.Class<?> source)` Returns the list of variants that can be converted from a given object class.
`float` `score(java.lang.Object source, Variant target, UniformResource resource)` Scores the affinity of this helper with the source class.
`<T> float` `score(Representation source, java.lang.Class<T> target, UniformResource resource)` Scores the affinity of this helper with the source class.
`void` `setObjectMapper(org.codehaus.jackson.map.ObjectMapper objectMapper)` Sets the Jackson object mapper.
`<T> T` `toObject(Representation source, java.lang.Class<T> target, UniformResource resource)` Converts a Representation into a regular Java object.
`Representation` `toRepresentation(java.lang.Object source, Variant target, UniformResource resource)` Converts a regular Java object into a Representation.
`<T> void` `updatePreferences(java.util.List<Preference<MediaType>> preferences, java.lang.Class<T> entity)` Updates the preferences of the given `ClientInfo` object with conversion capabilities for the given entity class.

### Methods inherited from class org.restlet.engine.converter.ConverterHelper

`addObjectClass, addVariant, updatePreferences`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### JacksonConverter

    public JacksonConverter()

### Method Detail

#### create

    protected <T> JacksonRepresentation<T> create(MediaType mediaType,
                                      T source)

Creates the marshaling `JacksonRepresentation`.

Type Parameters:
  `T` -
Parameters:
  `mediaType` - The target media type.
  `source` - The source object to marshal.
Returns:
  The marshaling `JacksonRepresentation`.

#### create

    protected <T> JacksonRepresentation<T> create(Representation source,
                                      java.lang.Class<T> objectClass)

Creates the unmarshaling `JacksonRepresentation`.

Type Parameters:
  `T` -
Parameters:
  `source` - The source representation to unmarshal.
  `objectClass` - The object class to instantiate.
Returns:
  The unmarshaling `JacksonRepresentation`.

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

#### getObjectClasses

    public java.util.List<java.lang.Class<?>> getObjectClasses(Variant source)

Description copied from class: `ConverterHelper`
Returns the list of object classes that can be converted from a given variant.

Specified by:
  `getObjectClasses` in class `ConverterHelper`
Parameters:
  `source` - The source variant.
Returns:
  The list of object class that can be converted.

#### getObjectMapper

    public org.codehaus.jackson.map.ObjectMapper getObjectMapper()

Returns the modifiable Jackson object mapper. Useful to customize mappings.

Returns:
  The modifiable Jackson object mapper.

#### getVariants

    public java.util.List<VariantInfo> getVariants(java.lang.Class<?> source)

Description copied from class: `ConverterHelper`
Returns the list of variants that can be converted from a given object class. The preferred variant should be set in first position.

Specified by:
  `getVariants` in class `ConverterHelper`
Parameters:
  `source` - The source object class.
Returns:
  The list of variants that can be converted.

#### score

    public float score(java.lang.Object source,
              Variant target,
              UniformResource resource)

Description copied from class: `ConverterHelper`
Scores the affinity of this helper with the source class.

Specified by:
  `score` in class `ConverterHelper`
Parameters:
  `source` - The source object to convert.
  `target` - The expected representation metadata.
  `resource` - The calling resource.
Returns:
  The affinity score of this helper.

#### score

    public <T> float score(Representation source,
                  java.lang.Class<T> target,
                  UniformResource resource)

Description copied from class: `ConverterHelper`
Scores the affinity of this helper with the source class.

Specified by:
  `score` in class `ConverterHelper`
Parameters:
  `source` - The source representation to convert.
  `target` - The expected class of the Java object.
  `resource` - The calling resource.
Returns:
  The affinity score of this helper.

#### setObjectMapper

    public void setObjectMapper(org.codehaus.jackson.map.ObjectMapper objectMapper)

Sets the Jackson object mapper.

Parameters:
  `objectMapper` - The Jackson object mapper.

#### toObject

    public <T> T toObject(Representation source,
                 java.lang.Class<T> target,
                 UniformResource resource)
               throws java.io.IOException

Description copied from class: `ConverterHelper`
Converts a Representation into a regular Java object.

Specified by:
  `toObject` in class `ConverterHelper`
Type Parameters:
  `T` - The expected class of the Java object.
Parameters:
  `source` - The source representation to convert.
  `target` - The expected class of the Java object.
  `resource` - The calling resource.
Returns:
  The converted Java object.
Throws:
  `java.io.IOException`

#### toRepresentation

    public Representation toRepresentation(java.lang.Object source,
                                  Variant target,
                                  UniformResource resource)

Description copied from class: `ConverterHelper`
Converts a regular Java object into a Representation.

Specified by:
  `toRepresentation` in class `ConverterHelper`
Parameters:
  `source` - The source object to convert.
  `target` - The expected representation metadata.
  `resource` - The calling resource.
Returns:
  The converted representation.

#### updatePreferences

    public <T> void updatePreferences(java.util.List<Preference<MediaType>> preferences,
                             java.lang.Class<T> entity)

Description copied from class: `ConverterHelper`
Updates the preferences of the given `ClientInfo` object with conversion capabilities for the given entity class.

Overrides:
  `updatePreferences` in class `ConverterHelper`
Parameters:
  `preferences` - The media type preferences.
  `entity` - The entity class to convert.