org.restlet.service

## Class ConverterService

- java.lang.Object
- - org.restlet.service.Service
  - - org.restlet.service.ConverterService

    public class ConverterService
    extends Service

Application service converting between representation and regular Java objects. The conversion can work in both directions.
By default, the following conversions are supported. Additional ones can be plugged into the engine.

Author:
  Jerome Louvel

### Constructor Summary

Constructors
Constructor and Description
`ConverterService()` Constructor.
`ConverterService(boolean enabled)` Constructor.

### Method Summary

Methods
`java.util.List<java.lang.Class<?>>` `getObjectClasses(Variant source)` Returns the list of object classes that can be converted from a given variant.
`java.util.List<? extends Variant>` `getVariants(java.lang.Class<?> source, Variant target)` Returns the list of variants that can be converted from a given object class.
`java.lang.Object` `toObject(Representation source)` Converts a Representation into a regular Java object.
`<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)` Converts a regular Java object into a Representation.
`Representation` `toRepresentation(java.lang.Object source, Variant target, UniformResource resource)` Converts a regular Java object into a Representation.
`void` `updatePreferences(java.util.List<Preference<MediaType>> preferences, java.lang.Class<?> entity)` Updates the media type preferences with available conversion capabilities for the given entity class.

### Methods inherited from class org.restlet.service.Service

`createInboundFilter, createOutboundFilter, getContext, isEnabled, isStarted, isStopped, setContext, setEnabled, start, stop`

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

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

### Constructor Detail

#### ConverterService

    public ConverterService()

Constructor.

#### ConverterService

    public ConverterService(boolean enabled)

Constructor.

Parameters:
  `enabled` - True if the service has been enabled.

### Method Detail

#### getObjectClasses

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

Returns the list of object classes that can be converted from a given variant.

Parameters:
  `source` - The source variant.
Returns:
  The list of object class that can be converted.

#### getVariants

    public java.util.List<? extends Variant> getVariants(java.lang.Class<?> source,
                                                Variant target)

Returns the list of variants that can be converted from a given object class.

Parameters:
  `source` - The source class.
  `target` - The expected representation metadata.
Returns:
  The list of variants that can be converted.

#### toObject

    public java.lang.Object toObject(Representation source)
                              throws java.io.IOException

Converts a Representation into a regular Java object.

Parameters:
  `source` - The source representation to convert.
Returns:
  The converted Java object.
Throws:
  `java.io.IOException`

#### toObject

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

Converts a Representation into a regular Java object.

Type Parameters:
  `T` - The expected class of the Java object.
Parameters:
  `source` - The source representation to convert.
  `target` - The target class of the Java object.
  `resource` - The parent resource.
Returns:
  The converted Java object.
Throws:
  `java.io.IOException`

#### toRepresentation

    public Representation toRepresentation(java.lang.Object source)

Converts a regular Java object into a Representation. The converter will use the preferred variant of the selected converter.

Parameters:
  `source` - The source object to convert.
Returns:
  The converted representation.

#### toRepresentation

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

Converts a regular Java object into a Representation.

Parameters:
  `source` - The source object to convert.
  `target` - The target representation variant.
  `resource` - The parent resource.
Returns:
  The converted representation.

#### updatePreferences

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

Updates the media type preferences with available conversion capabilities for the given entity class.

Parameters:
  `preferences` - The media type preferences.
  `entity` - The entity class to convert.