Package jadex.serialization.serializers
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 Summary
FieldsModifier and TypeFieldDescriptionprotected jadex.common.transformation.IStringConverterThe basic string converter.protected booleanThe debug flag.List<jadex.common.transformation.traverser.ITraverseProcessor>The read processors.static final intThe serializer id.static final StringList<jadex.common.transformation.traverser.ITraverseProcessor>The write processors.Fields inherited from interface jadex.common.transformation.IStringConverter
TYPE_BASIC, TYPE_JSON, TYPE_XML -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddProcessor(jadex.common.transformation.traverser.ITraverseProcessor read, jadex.common.transformation.traverser.ITraverseProcessor write) Add a read/write processor pair.convertBasicType(String val, Class<?> targettype, ClassLoader cl, Object context) convertObject(Object val, Class<?> type, ClassLoader cl, Object context) Convert an object to a string.convertString(String val, Class<?> type, ClassLoader cl, Object context) Convert a string to an object.decode(byte[] bytes, ClassLoader classloader, jadex.common.transformation.traverser.ITraverseProcessor[] postprocs, jadex.common.transformation.traverser.IErrorReporter rep, Object usercontext) Decode an object.decode(InputStream is, ClassLoader classloader, jadex.common.transformation.traverser.ITraverseProcessor[] postprocs, jadex.common.transformation.traverser.IErrorReporter rep, Object usercontext) Decode an object.voidencode(OutputStream os, Object val, ClassLoader classloader, jadex.common.transformation.traverser.ITraverseProcessor[] preprocs, Object usercontext) Encode data with the serializer.byte[]encode(Object val, ClassLoader classloader, jadex.common.transformation.traverser.ITraverseProcessor[] preprocs, Object usercontext) Encode data with the serializer.intGet the serializer id.getType()Get the type of string that can be processed (xml, json, plain).booleanisSupportedType(Class<?> clazz) Test if the type can be converted.
-
Field Details
-
SERIALIZER_ID
public static final int SERIALIZER_IDThe serializer id.- See Also:
-
TYPE
- See Also:
-
DEBUG
protected boolean DEBUGThe debug flag. -
writeprocs
The write processors. -
readprocs
The read processors. -
converter
protected jadex.common.transformation.IStringConverter converterThe basic string converter.
-
-
Constructor Details
-
JadexJsonSerializer
public JadexJsonSerializer()Create a new serializer.
-
-
Method Details
-
getSerializerId
public int getSerializerId()Get the serializer id.- Specified by:
getSerializerIdin interfaceISerializer- 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:
encodein interfaceISerializer- 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:
decodein interfaceISerializer- Returns:
- The decoded object.
- Throws:
IOException
-
convertString
Convert a string to an object.- Specified by:
convertStringin interfacejadex.common.transformation.IStringConverter- Parameters:
val- The string.type- The target type.context- The context.- Returns:
- The object.
-
convertBasicType
-
convertObject
Convert an object to a string.- Specified by:
convertObjectin interfacejadex.common.transformation.IStringConverter- Parameters:
val- The object.type- The encoding type.context- The context.- Returns:
- The object.
-
getType
Get the type of string that can be processed (xml, json, plain).- Specified by:
getTypein interfacejadex.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
Test if the type can be converted.- Specified by:
isSupportedTypein interfacejadex.common.transformation.IStringConverter- Parameters:
clazz- The class.- Returns:
- True if can be converted.
-