Class ObjectRepresentation<T extends Serializable>

Type Parameters:
T - The class to serialize, see Serializable

public class ObjectRepresentation<T extends Serializable> extends OutputRepresentation
Representation based on a serializable Java object.
It supports binary representations of JavaBeans using the ObjectInputStream and ObjectOutputStream classes. In this case, it handles representations having the following media type: MediaType.APPLICATION_JAVA_OBJECT ("application/x-java-serialized-object"). It also supports textual representations of JavaBeans using the XMLEncoder and XMLDecoder classes. In this case, it handles representations having the following media type: MediaType.APPLICATION_JAVA_OBJECT_XML ("application/x-java-serialized-object+xml").

SECURITY WARNING: The usage of XMLDecoder when deserializing XML presentations from untrusted sources can lead to malicious attacks. As pointed here, the XMLDecoder is able to force the JVM to execute unwanted Java code described inside the XML file. Thus, the support of such format has been disabled by default. You can activate this support by turning on the following system property: org.restlet.representation.ObjectRepresentation.VARIANT_OBJECT_XML_SUPPORTED.

SECURITY WARNING: The usage of ObjectInputStream when deserializing binary presentations from untrusted sources can lead to malicious attacks. As pointed here, the ObjectInputStream is able to force the JVM to execute unwanted Java code. Thus, the support of such format has been disabled by default. You can activate this support by turning on the following system property: "org.restlet.representation.ObjectRepresentation .VARIANT_OBJECT_BINARY_SUPPORTED".
Author:
Jerome Louvel
  • Field Details

    • VARIANT_OBJECT_XML_SUPPORTED

      public static boolean VARIANT_OBJECT_XML_SUPPORTED
      Indicates whether the JavaBeans XML deserialization is supported or not.
    • VARIANT_OBJECT_BINARY_SUPPORTED

      public static boolean VARIANT_OBJECT_BINARY_SUPPORTED
      Indicates whether the JavaBeans binary deserialization is supported or not.
  • Constructor Details

  • Method Details

    • getObject

      public T getObject() throws IOException
      Returns the represented object.
      Returns:
      The represented object.
      Throws:
      IOException
    • release

      public void release()
      Releases the represented object.
      Overrides:
      release in class Representation
    • setObject

      public void setObject(T object)
      Sets the represented object.
      Parameters:
      object - The represented object.
    • write

      public void write(OutputStream outputStream) throws IOException
      Description copied from class: Representation
      Writes the representation to a byte stream. This method is ensured to write the full content for each invocation unless it is a transient representation, in which case an exception is thrown.

      Note that the class implementing this method shouldn't flush or close the given OutputStream after writing to it as this will be handled by the Restlet connectors automatically.
      Specified by:
      write in class Representation
      Parameters:
      outputStream - The output stream.
      Throws:
      IOException