Class JadexJsonSerializer

java.lang.Object
jadex.serialization.serializers.JadexJsonSerializer
All Implemented Interfaces:
jadex.common.transformation.IStringConverter, ISerializer

public class JadexJsonSerializer extends Object implements ISerializer, jadex.common.transformation.IStringConverter
The Jadex JSON serializer. Codec supports parallel calls of multiple concurrent clients (no method synchronization necessary). Converts object -> byte[] and byte[] -> object.
  • Field Details

    • SERIALIZER_ID

      public static final int SERIALIZER_ID
      The serializer id.
      See Also:
    • TYPE

      public static final String TYPE
      See Also:
    • DEBUG

      protected boolean DEBUG
      The debug flag.
    • writeprocs

      public List<jadex.common.transformation.traverser.ITraverseProcessor> writeprocs
      The write processors.
    • readprocs

      public List<jadex.common.transformation.traverser.ITraverseProcessor> readprocs
      The read processors.
    • converter

      protected jadex.common.transformation.IStringConverter converter
      The basic string converter.
  • Constructor Details

    • JadexJsonSerializer

      public JadexJsonSerializer()
      Create a new serializer.
  • Method Details

    • getSerializerId

      public int getSerializerId()
      Get the serializer id.
      Specified by:
      getSerializerId in interface ISerializer
      Returns:
      The serializer id.
    • encode

      public void encode(OutputStream os, Object val, ClassLoader classloader, jadex.common.transformation.traverser.ITraverseProcessor[] preprocs, Object usercontext)
      Encode data with the serializer.
      Specified by:
      encode in interface ISerializer
      Parameters:
      os - The output stream for writing.
      val - The value.
      classloader - The classloader.
      preproc - The encoding preprocessors.
    • encode

      public byte[] encode(Object val, ClassLoader classloader, jadex.common.transformation.traverser.ITraverseProcessor[] preprocs, Object usercontext)
      Encode data with the serializer.
      Parameters:
      val - The value.
      classloader - The classloader.
      preproc - The encoding preprocessors.
      Returns:
      The encoded object.
    • decode

      public Object decode(byte[] bytes, ClassLoader classloader, jadex.common.transformation.traverser.ITraverseProcessor[] postprocs, jadex.common.transformation.traverser.IErrorReporter rep, Object usercontext)
      Decode an object.
      Returns:
      The decoded object.
      Throws:
      IOException
    • decode

      public Object decode(InputStream is, ClassLoader classloader, jadex.common.transformation.traverser.ITraverseProcessor[] postprocs, jadex.common.transformation.traverser.IErrorReporter rep, Object usercontext)
      Decode an object.
      Specified by:
      decode in interface ISerializer
      Returns:
      The decoded object.
      Throws:
      IOException
    • convertString

      public Object convertString(String val, Class<?> type, ClassLoader cl, Object context)
      Convert a string to an object.
      Specified by:
      convertString in interface jadex.common.transformation.IStringConverter
      Parameters:
      val - The string.
      type - The target type.
      context - The context.
      Returns:
      The object.
    • convertBasicType

      public Object convertBasicType(String val, Class<?> targettype, ClassLoader cl, Object context)
    • convertObject

      public String convertObject(Object val, Class<?> type, ClassLoader cl, Object context)
      Convert an object to a string.
      Specified by:
      convertObject in interface jadex.common.transformation.IStringConverter
      Parameters:
      val - The object.
      type - The encoding type.
      context - The context.
      Returns:
      The object.
    • getType

      public String getType()
      Get the type of string that can be processed (xml, json, plain).
      Specified by:
      getType in interface jadex.common.transformation.IStringConverter
      Returns:
      The object.
    • addProcessor

      public void addProcessor(jadex.common.transformation.traverser.ITraverseProcessor read, jadex.common.transformation.traverser.ITraverseProcessor write)
      Add a read/write processor pair.
    • isSupportedType

      public boolean isSupportedType(Class<?> clazz)
      Test if the type can be converted.
      Specified by:
      isSupportedType in interface jadex.common.transformation.IStringConverter
      Parameters:
      clazz - The class.
      Returns:
      True if can be converted.