Class GenericJsonSerializer<T>

java.lang.Object
de.iip_ecosphere.platform.transport.serialization.GenericJsonSerializer<T>
Type Parameters:
T - the class to be serialized
All Implemented Interfaces:
InputTypeTranslator<byte[],T>, OutputTypeTranslator<T,byte[]>, Serializer<T>, TypeTranslator<T,byte[]>

public class GenericJsonSerializer<T> extends Object implements Serializer<T>
A simple, generic, reusable JSON serializer.
Author:
Holger Eichelberger, SSE
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private Class<T>
     
    private de.iip_ecosphere.platform.support.json.Json
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Implements a simple generic JSON serializer.
  • Method Summary

    Modifier and Type
    Method
    Description
    clone(T origin)
    Creates a new value instance and copies the values from origin to the new instance.
    from(byte[] data)
    Deserializes a target value into a source value ("input from external").
    de.iip_ecosphere.platform.support.json.Json
    Returns the object mapper.
    The type to be handled by this serializer.
    byte[]
    to(T source)
    Translates a source value into a target value ("output to external").

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • mapper

      private de.iip_ecosphere.platform.support.json.Json mapper
    • cls

      private Class<T> cls
  • Constructor Details

    • GenericJsonSerializer

      public GenericJsonSerializer(Class<T> cls)
      Implements a simple generic JSON serializer.
      Parameters:
      cls - the class to be serialized
  • Method Details

    • getMapper

      public de.iip_ecosphere.platform.support.json.Json getMapper()
      Returns the object mapper.
      Returns:
      the mapper
    • from

      public T from(byte[] data) throws IOException
      Description copied from interface: InputTypeTranslator
      Deserializes a target value into a source value ("input from external").
      Specified by:
      from in interface InputTypeTranslator<byte[],T>
      Parameters:
      data - the data to be translated back
      Returns:
      the serialized object
      Throws:
      IOException - in case that serialization fails
    • to

      public byte[] to(T source) throws IOException
      Description copied from interface: OutputTypeTranslator
      Translates a source value into a target value ("output to external").
      Specified by:
      to in interface OutputTypeTranslator<T,byte[]>
      Parameters:
      source - the source value to be translated
      Returns:
      the target value
      Throws:
      IOException - in case that translation fails
    • clone

      public T clone(T origin) throws IOException
      Description copied from interface: Serializer
      Creates a new value instance and copies the values from origin to the new instance. Use the SerializerRegistry to implement cloning of nested object values.
      Specified by:
      clone in interface Serializer<T>
      Parameters:
      origin - the object to clone
      Returns:
      the cloned object
      Throws:
      IOException - in case that cloning/serialization operations fail
    • getType

      public Class<T> getType()
      Description copied from interface: Serializer
      The type to be handled by this serializer.
      Specified by:
      getType in interface Serializer<T>
      Returns:
      the type