Package 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, JSON Smile, CSV, XML, YAML and Representation classes based on Jackson.
-
-
Field Summary
Fields Modifier and Type Field Description private static VariantInfoVARIANT_APPLICATION_XMLVariant with media type application/xml.private static VariantInfoVARIANT_APPLICATION_YAMLVariant with media type application/yaml.private static VariantInfoVARIANT_JSONVariant with media type application/json.private static VariantInfoVARIANT_JSON_SMILEVariant with media type application/x-json-smile.private static VariantInfoVARIANT_TEXT_CSVVariant with media type text/csv.private static VariantInfoVARIANT_TEXT_XMLVariant with media type text/xml.private static VariantInfoVARIANT_TEXT_YAMLVariant with media type text/yaml.
-
Constructor Summary
Constructors Constructor Description JacksonConverter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <T> JacksonRepresentation<T>create(MediaType mediaType, T source)Creates the marshalingJacksonRepresentation.protected <T> JacksonRepresentation<T>create(Representation source, java.lang.Class<T> objectClass)Creates the unmarshalingJacksonRepresentation.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<VariantInfo>getVariants(java.lang.Class<?> source)Returns the list of variants that can be converted from a given object class.protected booleanisCompatible(Variant variant)Indicates if the given variant is compatible with the media types supported by this converter.floatscore(java.lang.Object source, Variant target, Resource resource)Scores the affinity of this helper with the source class.<T> floatscore(Representation source, java.lang.Class<T> target, Resource resource)Scores the affinity of this helper with the source class.<T> TtoObject(Representation source, java.lang.Class<T> target, Resource resource)Converts a Representation into a regular Java object.RepresentationtoRepresentation(java.lang.Object source, Variant target, Resource resource)Converts a regular Java object into a Representation.<T> voidupdatePreferences(java.util.List<Preference<MediaType>> preferences, java.lang.Class<T> entity)Updates the preferences of the givenClientInfoobject with conversion capabilities for the given entity class.-
Methods inherited from class org.restlet.engine.converter.ConverterHelper
addObjectClass, addVariant, addVariants, getVariants, updatePreferences
-
-
-
-
Field Detail
-
VARIANT_APPLICATION_XML
private static final VariantInfo VARIANT_APPLICATION_XML
Variant with media type application/xml.
-
VARIANT_APPLICATION_YAML
private static final VariantInfo VARIANT_APPLICATION_YAML
Variant with media type application/yaml.
-
VARIANT_JSON
private static final VariantInfo VARIANT_JSON
Variant with media type application/json.
-
VARIANT_JSON_SMILE
private static final VariantInfo VARIANT_JSON_SMILE
Variant with media type application/x-json-smile.
-
VARIANT_TEXT_CSV
private static final VariantInfo VARIANT_TEXT_CSV
Variant with media type text/csv.
-
VARIANT_TEXT_XML
private static final VariantInfo VARIANT_TEXT_XML
Variant with media type text/xml.
-
VARIANT_TEXT_YAML
private static final VariantInfo VARIANT_TEXT_YAML
Variant with media type text/yaml.
-
-
Method Detail
-
create
protected <T> JacksonRepresentation<T> create(MediaType mediaType, T source)
Creates the marshalingJacksonRepresentation.- 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 unmarshalingJacksonRepresentation.- Type Parameters:
T-- Parameters:
source- The source representation to unmarshal.objectClass- The object class to instantiate.- Returns:
- The unmarshaling
JacksonRepresentation.
-
getObjectClasses
public java.util.List<java.lang.Class<?>> getObjectClasses(Variant source)
Description copied from class:ConverterHelperReturns the list of object classes that can be converted from a given variant.- Specified by:
getObjectClassesin classConverterHelper- Parameters:
source- The source variant.- Returns:
- The list of object class that can be converted.
-
getVariants
public java.util.List<VariantInfo> getVariants(java.lang.Class<?> source)
Description copied from class:ConverterHelperReturns the list of variants that can be converted from a given object class. The preferred variant should be set in first position.- Specified by:
getVariantsin classConverterHelper- Parameters:
source- The source object class.- Returns:
- The list of variants that can be converted.
-
isCompatible
protected boolean isCompatible(Variant variant)
Indicates if the given variant is compatible with the media types supported by this converter.- Parameters:
variant- The variant.- Returns:
- True if the given variant is compatible with the media types supported by this converter.
-
score
public float score(java.lang.Object source, Variant target, Resource resource)Description copied from class:ConverterHelperScores the affinity of this helper with the source class.- Specified by:
scorein classConverterHelper- 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, Resource resource)
Description copied from class:ConverterHelperScores the affinity of this helper with the source class.- Specified by:
scorein classConverterHelper- 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.
-
toObject
public <T> T toObject(Representation source, java.lang.Class<T> target, Resource resource) throws java.io.IOException
Description copied from class:ConverterHelperConverts a Representation into a regular Java object.- Specified by:
toObjectin classConverterHelper- 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, Resource resource)
Description copied from class:ConverterHelperConverts a regular Java object into a Representation.- Specified by:
toRepresentationin classConverterHelper- 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:ConverterHelperUpdates the preferences of the givenClientInfoobject with conversion capabilities for the given entity class.- Overrides:
updatePreferencesin classConverterHelper- Parameters:
preferences- The media type preferences.entity- The entity class to convert.
-
-