Class JadexJsonSerializer
- java.lang.Object
-
- jadex.platform.service.serialization.serializers.JadexJsonSerializer
-
- All Implemented Interfaces:
ISerializer,IStringConverter
public class JadexJsonSerializer extends java.lang.Object implements ISerializer, IStringConverter
The Jadex JSON serializer. Codec supports parallel calls of multiple concurrent clients (no method synchronization necessary). Converts object -> byte[] and byte[] -> object.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classJadexJsonSerializer.JsonByteArrayReadProcessorprotected static classJadexJsonSerializer.JsonByteArrayWriteProcessor
-
Field Summary
Fields Modifier and Type Field Description protected booleanDEBUGThe debug flag.java.util.List<ITraverseProcessor>readprocsThe read processors.static intSERIALIZER_IDThe serializer id.static java.lang.StringTYPEjava.util.List<ITraverseProcessor>writeprocsThe write processors.-
Fields inherited from interface jadex.commons.transformation.IStringConverter
TYPE_BASIC, TYPE_JSON, TYPE_XML
-
-
Constructor Summary
Constructors Constructor Description JadexJsonSerializer()Create a new serializer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddProcessor(ITraverseProcessor read, ITraverseProcessor write)Add a read/write processor pair.java.lang.StringconvertObject(java.lang.Object val, java.lang.Class<?> type, java.lang.ClassLoader cl, java.lang.Object context)Convert an object to a string.java.lang.ObjectconvertString(java.lang.String val, java.lang.Class<?> type, java.lang.ClassLoader cl, java.lang.Object context)Convert a string to an object.java.lang.Objectdecode(byte[] bytes, java.lang.ClassLoader classloader, ITraverseProcessor[] postprocs, IErrorReporter rep, java.lang.Object usercontext)Decode an object.java.lang.Objectdecode(java.io.InputStream is, java.lang.ClassLoader classloader, ITraverseProcessor[] postprocs, IErrorReporter rep, java.lang.Object usercontext)Decode an object.byte[]encode(java.lang.Object val, java.lang.ClassLoader classloader, ITraverseProcessor[] preprocs, java.lang.Object usercontext)Encode data with the serializer.intgetSerializerId()Get the serializer id.java.lang.StringgetType()Get the type of string that can be processed (xml, json, plain).booleanisSupportedType(java.lang.Class<?> clazz)Test if the type can be converted.
-
-
-
Field Detail
-
SERIALIZER_ID
public static final int SERIALIZER_ID
The serializer id.- See Also:
- Constant Field Values
-
TYPE
public static final java.lang.String TYPE
- See Also:
- Constant Field Values
-
DEBUG
protected boolean DEBUG
The debug flag.
-
writeprocs
public java.util.List<ITraverseProcessor> writeprocs
The write processors.
-
readprocs
public java.util.List<ITraverseProcessor> readprocs
The read processors.
-
-
Method Detail
-
getSerializerId
public int getSerializerId()
Get the serializer id.- Specified by:
getSerializerIdin interfaceISerializer- Returns:
- The serializer id.
-
encode
public byte[] encode(java.lang.Object val, java.lang.ClassLoader classloader, ITraverseProcessor[] preprocs, java.lang.Object usercontext)Encode data with the serializer.- Specified by:
encodein interfaceISerializer- Parameters:
val- The value.classloader- The classloader.preproc- The encoding preprocessors.- Returns:
- The encoded object.
-
decode
public java.lang.Object decode(byte[] bytes, java.lang.ClassLoader classloader, ITraverseProcessor[] postprocs, IErrorReporter rep, java.lang.Object usercontext)Decode an object.- Specified by:
decodein interfaceISerializer- Parameters:
bytes- The value bytes as byte array or input stream.- Returns:
- The decoded object.
- Throws:
java.io.IOException
-
decode
public java.lang.Object decode(java.io.InputStream is, java.lang.ClassLoader classloader, ITraverseProcessor[] postprocs, IErrorReporter rep, java.lang.Object usercontext)Decode an object.- Specified by:
decodein interfaceISerializer- Returns:
- The decoded object.
- Throws:
java.io.IOException
-
convertString
public java.lang.Object convertString(java.lang.String val, java.lang.Class<?> type, java.lang.ClassLoader cl, java.lang.Object context)Convert a string to an object.- Specified by:
convertStringin interfaceIStringConverter- Parameters:
val- The string.type- The target type.context- The context.- Returns:
- The object.
-
convertObject
public java.lang.String convertObject(java.lang.Object val, java.lang.Class<?> type, java.lang.ClassLoader cl, java.lang.Object context)Convert an object to a string.- Specified by:
convertObjectin interfaceIStringConverter- Parameters:
val- The object.type- The encoding type.context- The context.- Returns:
- The object.
-
getType
public java.lang.String getType()
Get the type of string that can be processed (xml, json, plain).- Specified by:
getTypein interfaceIStringConverter- Returns:
- The object.
-
addProcessor
public void addProcessor(ITraverseProcessor read, ITraverseProcessor write)
Add a read/write processor pair.
-
isSupportedType
public boolean isSupportedType(java.lang.Class<?> clazz)
Test if the type can be converted.- Specified by:
isSupportedTypein interfaceIStringConverter- Parameters:
clazz- The class.- Returns:
- True if can be converted.
-
-