Class GenericJsonToStringTranslator<T>

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

public class GenericJsonToStringTranslator<T> extends Object implements TypeTranslator<T,String>
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.
    GenericJsonToStringTranslator(Class<T> cls, de.iip_ecosphere.platform.support.json.Json mapper)
    Implements a simple generic JSON serializer.
  • Method Summary

    Modifier and Type
    Method
    Description
    from(String data)
    Deserializes a target value into a source value ("input from external").
    de.iip_ecosphere.platform.support.json.Json
    Returns the object mapper, e.g., for further customization.
    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

    • GenericJsonToStringTranslator

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

      public GenericJsonToStringTranslator(Class<T> cls, de.iip_ecosphere.platform.support.json.Json mapper)
      Implements a simple generic JSON serializer.
      Parameters:
      cls - the class to be serialized
      mapper - the object mapper to use
  • Method Details

    • getMapper

      public de.iip_ecosphere.platform.support.json.Json getMapper()
      Returns the object mapper, e.g., for further customization.
      Returns:
      the mapper
    • from

      public T from(String 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<String,T>
      Parameters:
      data - the data to be translated back
      Returns:
      the serialized object
      Throws:
      IOException - in case that serialization fails
    • to

      public String 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,String>
      Parameters:
      source - the source value to be translated
      Returns:
      the target value
      Throws:
      IOException - in case that translation fails