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 class
JadexJsonSerializer.JsonByteArrayReadProcessor
protected static class
JadexJsonSerializer.JsonByteArrayWriteProcessor
-
Field Summary
Fields Modifier and Type Field Description protected boolean
DEBUG
The debug flag.java.util.List<ITraverseProcessor>
readprocs
The read processors.static int
SERIALIZER_ID
The serializer id.static java.lang.String
TYPE
java.util.List<ITraverseProcessor>
writeprocs
The 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 void
addProcessor(ITraverseProcessor read, ITraverseProcessor write)
Add a read/write processor pair.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.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.java.lang.Object
decode(byte[] bytes, java.lang.ClassLoader classloader, ITraverseProcessor[] postprocs, IErrorReporter rep, java.lang.Object usercontext)
Decode an object.java.lang.Object
decode(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.int
getSerializerId()
Get the serializer id.java.lang.String
getType()
Get the type of string that can be processed (xml, json, plain).boolean
isSupportedType(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:
getSerializerId
in 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:
encode
in 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:
decode
in 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:
decode
in 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:
convertString
in 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:
convertObject
in 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:
getType
in 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:
isSupportedType
in interfaceIStringConverter
- Parameters:
clazz
- The class.- Returns:
- True if can be converted.
-
-