Package 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.StreamRepresentation
org.restlet.representation.OutputRepresentation
org.restlet.ext.jackson.JacksonRepresentation<T>
- Type Parameters:
T- The type to wrap.
public class JacksonRepresentation<T>
extends org.restlet.representation.OutputRepresentation
Representation based on the Jackson library. It can serialize and deserialize
automatically in JSON, JSON binary (Smile), XML, YAML and CSV.
SECURITY WARNING: Using XML parsers configured to not prevent nor limit document type definition (DTD) entity resolution can expose the parser to an XML Entity Expansion injection attack.
SECURITY WARNING: Using XML parsers configured to not prevent nor limit document type definition (DTD) entity resolution can expose the parser to an XML Entity Expansion injection attack.
- Author:
- Jerome Louvel
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanTrue for expanding entity references when parsing XML representations.static final booleanTrue for validating DTD documents when parsing XML representations.Fields inherited from class org.restlet.representation.Representation
UNKNOWN_SIZE -
Constructor Summary
ConstructorsConstructorDescriptionJacksonRepresentation(org.restlet.data.MediaType mediaType, T object) Constructor.JacksonRepresentation(org.restlet.representation.Representation representation, Class<T> objectClass) Constructor.JacksonRepresentation(T object) Constructor for the JSON media type. -
Method Summary
Modifier and TypeMethodDescriptionprotected com.fasterxml.jackson.dataformat.csv.CsvSchemacreateCsvSchema(com.fasterxml.jackson.dataformat.csv.CsvMapper csvMapper) Creates a Jackson CSV schema based on a mapper and the current object class.protected com.fasterxml.jackson.databind.ObjectMapperCreates a Jackson object mapper based on a media type.protected com.fasterxml.jackson.databind.ObjectReaderCreates a Jackson object reader based on a mapper.protected com.fasterxml.jackson.databind.ObjectWriterCreates a Jackson object writer based on a mapper.com.fasterxml.jackson.dataformat.csv.CsvSchemaReturns the modifiable Jackson CSV schema.Returns the wrapped object, deserializing the representation with Jackson if necessary.Returns the object class to instantiate.com.fasterxml.jackson.databind.ObjectMapperReturns the modifiable Jackson object mapper.com.fasterxml.jackson.databind.ObjectReaderReturns the modifiable Jackson object reader.com.fasterxml.jackson.databind.ObjectWriterReturns the modifiable Jackson object writer.booleanIndicates if the parser expands entity reference nodes.booleanIndicates the desire for validating this type of XML representations against an XML schema if one is referenced within the contents.voidsetCsvSchema(com.fasterxml.jackson.dataformat.csv.CsvSchema csvSchema) Sets the Jackson CSV schema.voidsetExpandingEntityRefs(boolean expandEntityRefs) Indicates if the parser expands entity reference nodes.voidSets the object to format.voidsetObjectClass(Class<T> objectClass) Sets the object class to instantiate.voidsetObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) Sets the Jackson object mapper.voidsetObjectReader(com.fasterxml.jackson.databind.ObjectReader objectReader) Sets the Jackson object reader.voidsetObjectWriter(com.fasterxml.jackson.databind.ObjectWriter objectWriter) Sets the Jackson object writer.voidsetValidatingDtd(boolean validating) Indicates the desire for validating this type of XML representations against an XML schema if one is referenced within the contents.voidwrite(OutputStream outputStream) Methods inherited from class org.restlet.representation.OutputRepresentation
getStreamMethods inherited from class org.restlet.representation.StreamRepresentation
getReader, writeMethods inherited from class org.restlet.representation.Representation
append, exhaust, getAvailableSize, getDigest, getDisposition, getExpirationDate, getRange, getSize, getText, hasKnownSize, isAvailable, isEmpty, isTransient, release, setAvailable, setDigest, setDisposition, setExpirationDate, setRange, setSize, setTransientMethods inherited from class org.restlet.representation.RepresentationInfo
getModificationDate, getTag, setModificationDate, setTagMethods inherited from class org.restlet.representation.Variant
createClientInfo, equals, getCharacterSet, getEncodings, getLanguages, getLocationRef, getMediaType, hashCode, includes, isCompatible, setCharacterSet, setEncodings, setLanguages, setLocationRef, setLocationRef, setMediaType, toString
-
Field Details
-
XML_EXPANDING_ENTITY_REFS
public static final boolean XML_EXPANDING_ENTITY_REFSTrue for expanding entity references when parsing XML representations. Default value provided by system property "org.restlet.ext.xml.expandingEntityRefs", false by default. -
XML_VALIDATING_DTD
public static final boolean XML_VALIDATING_DTDTrue for validating DTD documents when parsing XML representations. Default value provided by system property "org.restlet.ext.xml.validatingDtd", false by default.
-
-
Constructor Details
-
JacksonRepresentation
Constructor.- Parameters:
mediaType- The target media type.object- The object to format.
-
JacksonRepresentation
public JacksonRepresentation(org.restlet.representation.Representation representation, Class<T> objectClass) Constructor.- Parameters:
representation- The representation to parse.objectClass- The object class to instantiate.
-
JacksonRepresentation
Constructor for the JSON media type.- Parameters:
object- The object to format.
-
-
Method Details
-
createCsvSchema
protected com.fasterxml.jackson.dataformat.csv.CsvSchema createCsvSchema(com.fasterxml.jackson.dataformat.csv.CsvMapper csvMapper) Creates a Jackson CSV schema based on a mapper and the current object class.- Parameters:
csvMapper- The source CSV mapper.- Returns:
- A Jackson CSV schema
-
createObjectMapper
protected com.fasterxml.jackson.databind.ObjectMapper createObjectMapper()Creates a Jackson object mapper based on a media type. It supports JSON, JSON Smile, XML, YAML and CSV.- Returns:
- The Jackson object mapper.
-
createObjectReader
protected com.fasterxml.jackson.databind.ObjectReader createObjectReader()Creates a Jackson object reader based on a mapper. Has a special handling for CSV media types.- Returns:
- The Jackson object reader.
-
createObjectWriter
protected com.fasterxml.jackson.databind.ObjectWriter createObjectWriter()Creates a Jackson object writer based on a mapper. Has a special handling for CSV media types.- Returns:
- The Jackson object writer.
-
getCsvSchema
public com.fasterxml.jackson.dataformat.csv.CsvSchema getCsvSchema()Returns the modifiable Jackson CSV schema.- Returns:
- The modifiable Jackson CSV schema.
-
getObject
Returns the wrapped object, deserializing the representation with Jackson if necessary.- Returns:
- The wrapped object.
- Throws:
IOException
-
getObjectClass
Returns the object class to instantiate.- Returns:
- The object class to instantiate.
-
getObjectMapper
public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()Returns the modifiable Jackson object mapper. Useful to customize mappings.- Returns:
- The modifiable Jackson object mapper.
-
getObjectReader
public com.fasterxml.jackson.databind.ObjectReader getObjectReader()Returns the modifiable Jackson object reader. Useful to customize deserialization.- Returns:
- The modifiable Jackson object reader.
-
getObjectWriter
public com.fasterxml.jackson.databind.ObjectWriter getObjectWriter()Returns the modifiable Jackson object writer. Useful to customize serialization.- Returns:
- The modifiable Jackson object writer.
-
isExpandingEntityRefs
public boolean isExpandingEntityRefs()Indicates if the parser expands entity reference nodes. By default, the value of this is set to true.- Returns:
- True if the parser expands entity reference nodes.
-
isValidatingDtd
public boolean isValidatingDtd()Indicates the desire for validating this type of XML representations against an XML schema if one is referenced within the contents.- Returns:
- True if the schema-based validation is enabled.
-
setCsvSchema
public void setCsvSchema(com.fasterxml.jackson.dataformat.csv.CsvSchema csvSchema) Sets the Jackson CSV schema.- Parameters:
csvSchema- The Jackson CSV schema.
-
setExpandingEntityRefs
public void setExpandingEntityRefs(boolean expandEntityRefs) Indicates if the parser expands entity reference nodes. By default, the value of this is set to true.- Parameters:
expandEntityRefs- True if the parser expands entity reference nodes.
-
setObject
Sets the object to format.- Parameters:
object- The object to format.
-
setObjectClass
Sets the object class to instantiate.- Parameters:
objectClass- The object class to instantiate.
-
setObjectMapper
public void setObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) Sets the Jackson object mapper.- Parameters:
objectMapper- The Jackson object mapper.
-
setObjectReader
public void setObjectReader(com.fasterxml.jackson.databind.ObjectReader objectReader) Sets the Jackson object reader.- Parameters:
objectReader- The Jackson object reader.
-
setObjectWriter
public void setObjectWriter(com.fasterxml.jackson.databind.ObjectWriter objectWriter) Sets the Jackson object writer.- Parameters:
objectWriter- The Jackson object writer.
-
setValidatingDtd
public void setValidatingDtd(boolean validating) Indicates the desire for validating this type of XML representations against an XML schema if one is referenced within the contents.- Parameters:
validating- The new validation flag to set.
-
write
- Specified by:
writein classorg.restlet.representation.Representation- Throws:
IOException
-