Class JacksonSerder


  • public final class JacksonSerder
    extends java.lang.Object
    The type exposes APIs for serialization and deserialization using Jackson.
    • Constructor Summary

      Constructors 
      Constructor Description
      JacksonSerder()
      Creates a new JacksonAdapter instance with default mapper settings.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static JacksonSerder createDefault()
      maintain singleton instance of the default serializer adapter.
      <T> T deserialize​(java.io.InputStream inputStream, java.lang.reflect.Type type, SerdeEncoding encoding)
      Deserializes a byte[] into a T object.
      <T> T deserialize​(java.lang.String value, java.lang.reflect.Type type, SerdeEncoding encoding)
      Deserializes a string into a T object.
      <T> T deserialize​(java.util.Map<java.lang.String,​java.lang.String> headers, java.lang.reflect.Type deserializedHeadersType)
      Deserialize the provided headers returned from a REST API to an entity instance declared as the model to hold 'Matching' headers.
      java.lang.String serialize​(java.lang.Object object, SerdeEncoding encoding)
      Serializes an object into a string.
      void serialize​(java.lang.Object object, SerdeEncoding encoding, java.io.OutputStream outputStream)
      Serializes an object and writes its output into an OutputStream.
      java.lang.String serializeList​(java.util.List<?> list, SerdeCollectionFormat format)
      Serializes a list into a string with the delimiter specified with the Swagger collection format joining each individual serialized items in the list.
      java.lang.String serializeRaw​(java.lang.Object object)
      Serializes an object into a raw string.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JacksonSerder

        public JacksonSerder()
        Creates a new JacksonAdapter instance with default mapper settings.
    • Method Detail

      • createDefault

        public static JacksonSerder createDefault()
        maintain singleton instance of the default serializer adapter.
        Returns:
        the default serializer
      • serialize

        public java.lang.String serialize​(java.lang.Object object,
                                          SerdeEncoding encoding)
                                   throws java.io.IOException
        Serializes an object into a string.
        Parameters:
        object - the object to serialize
        encoding - the encoding to use for serialization
        Returns:
        the serialized string. Null if the object to serialize is null
        Throws:
        java.io.IOException - exception from serialization
      • serialize

        public void serialize​(java.lang.Object object,
                              SerdeEncoding encoding,
                              java.io.OutputStream outputStream)
                       throws java.io.IOException
        Serializes an object and writes its output into an OutputStream.
        Parameters:
        object - The object to serialize.
        encoding - The encoding to use for serialization.
        outputStream - The OutputStream where the serialized object will be written.
        Throws:
        java.io.IOException - exception from serialization
      • serializeRaw

        public java.lang.String serializeRaw​(java.lang.Object object)
        Serializes an object into a raw string. The leading and trailing quotes will be trimmed.
        Parameters:
        object - the object to serialize
        Returns:
        the serialized string. Null if the object to serialize is null
      • serializeList

        public java.lang.String serializeList​(java.util.List<?> list,
                                              SerdeCollectionFormat format)
        Serializes a list into a string with the delimiter specified with the Swagger collection format joining each individual serialized items in the list.
        Parameters:
        list - the list to serialize
        format - the Swagger collection format
        Returns:
        the serialized string
      • deserialize

        public <T> T deserialize​(java.lang.String value,
                                 java.lang.reflect.Type type,
                                 SerdeEncoding encoding)
                          throws java.io.IOException
        Deserializes a string into a T object.
        Type Parameters:
        T - the type of the deserialized object
        Parameters:
        value - the string value to deserialize
        type - the type to deserialize
        encoding - the encoding used in the serialized value
        Returns:
        the deserialized object
        Throws:
        java.io.IOException - exception from reading value to deserialize
        SerdeParseException - exception from deserialization
      • deserialize

        public <T> T deserialize​(java.io.InputStream inputStream,
                                 java.lang.reflect.Type type,
                                 SerdeEncoding encoding)
                          throws java.io.IOException
        Deserializes a byte[] into a T object.
        Type Parameters:
        T - The type of the deserialized object.
        Parameters:
        inputStream - The InputStream containing the serialized object data to deserialize.
        type - The type to deserialize.
        encoding - The encoding used to serialize value.
        Returns:
        The deserialized object, or null if it cannot be deserialized.
        Throws:
        java.io.IOException - exception from deserialization
        SerdeParseException - exception from deserialization
      • deserialize

        public <T> T deserialize​(java.util.Map<java.lang.String,​java.lang.String> headers,
                                 java.lang.reflect.Type deserializedHeadersType)
                          throws java.io.IOException
        Deserialize the provided headers returned from a REST API to an entity instance declared as the model to hold 'Matching' headers. 'Matching' headers are the REST API returned headers those with:
        1. header names same as name of a properties in the entity.
        2. header names start with value of HeaderCollection annotation applied to the properties in the entity.
        Type Parameters:
        T - the type of the deserialized object
        Parameters:
        headers - the REST API returned headers
        deserializedHeadersType - the type to deserialize
        Returns:
        instance of header entity type created based on provided headers, if header entity model does not not exists then return null
        Throws:
        java.io.IOException - If an I/O error occurs