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.
Author:
Jerome Louvel
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final boolean
    True for expanding entity references when parsing XML representations.
    static final boolean
    True for validating DTD documents when parsing XML representations.

    Fields inherited from class org.restlet.representation.Representation

    UNKNOWN_SIZE
  • Constructor Summary

    Constructors
    Constructor
    Description
    JacksonRepresentation(org.restlet.data.MediaType mediaType, T object)
    Constructor.
    JacksonRepresentation(org.restlet.representation.Representation representation, Class<T> objectClass)
    Constructor.
    Constructor for the JSON media type.
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    protected com.fasterxml.jackson.databind.ObjectMapper
    Creates a Jackson object mapper based on a media type.
    protected com.fasterxml.jackson.databind.ObjectReader
    Creates a Jackson object reader based on a mapper.
    protected com.fasterxml.jackson.databind.ObjectWriter
    Creates a Jackson object writer based on a mapper.
    com.fasterxml.jackson.dataformat.csv.CsvSchema
    Returns 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.ObjectMapper
    Returns the modifiable Jackson object mapper.
    com.fasterxml.jackson.databind.ObjectReader
    Returns the modifiable Jackson object reader.
    com.fasterxml.jackson.databind.ObjectWriter
    Returns the modifiable Jackson object writer.
    boolean
    Indicates if the parser expands entity reference nodes.
    boolean
    Indicates the desire for validating this type of XML representations against an XML schema if one is referenced within the contents.
    void
    setCsvSchema(com.fasterxml.jackson.dataformat.csv.CsvSchema csvSchema)
    Sets the Jackson CSV schema.
    void
    setExpandingEntityRefs(boolean expandEntityRefs)
    Indicates if the parser expands entity reference nodes.
    void
    setObject(T object)
    Sets the object to format.
    void
    setObjectClass(Class<T> objectClass)
    Sets the object class to instantiate.
    void
    setObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
    Sets the Jackson object mapper.
    void
    setObjectReader(com.fasterxml.jackson.databind.ObjectReader objectReader)
    Sets the Jackson object reader.
    void
    setObjectWriter(com.fasterxml.jackson.databind.ObjectWriter objectWriter)
    Sets the Jackson object writer.
    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.
    void
    write(OutputStream outputStream)
     

    Methods inherited from class org.restlet.representation.OutputRepresentation

    getStream

    Methods inherited from class org.restlet.representation.StreamRepresentation

    getReader, write

    Methods 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, 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, getLanguages, getLocationRef, getMediaType, hashCode, includes, isCompatible, setCharacterSet, setEncodings, setLanguages, setLocationRef, setLocationRef, setMediaType, toString

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • XML_EXPANDING_ENTITY_REFS

      public static final boolean XML_EXPANDING_ENTITY_REFS
      True 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_DTD
      True 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

      public JacksonRepresentation(org.restlet.data.MediaType mediaType, T object)
      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

      public JacksonRepresentation(T object)
      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

      public T getObject() throws IOException
      Returns the wrapped object, deserializing the representation with Jackson if necessary.
      Returns:
      The wrapped object.
      Throws:
      IOException
    • getObjectClass

      public Class<T> 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

      public void setObject(T object)
      Sets the object to format.
      Parameters:
      object - The object to format.
    • setObjectClass

      public void setObjectClass(Class<T> objectClass)
      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

      public void write(OutputStream outputStream) throws IOException
      Specified by:
      write in class org.restlet.representation.Representation
      Throws:
      IOException