Package org.cakelab.json.codec
Class JSONCodec
- java.lang.Object
-
- org.cakelab.json.codec.JSONCodec
-
public class JSONCodec extends java.lang.Object
This class implements serialising/deserialising of Java objects from and to JSON strings.Multi-Threading
Not thread-safe.- Author:
- homac
-
-
Constructor Summary
Constructors Constructor Description JSONCodec()
Constructor using the default configuration.JSONCodec(JSONCodecConfiguration cfg)
Constructor using a specific configuration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> T
decodeObject(java.io.InputStream inputStream, java.lang.Class<T> targetType)
Decodes the given JSON string from input stream into a Java object of the given target type T.<T> T
decodeObject(java.io.InputStream inputStream, T targetObject)
Decodes the given JSON string from input stream into the given target object of type T.<T> T
decodeObject(java.lang.String jsonString, java.lang.Class<T> targetType)
Decodes the given JSON string into a Java object of the given target type T.<T> T
decodeObject(java.lang.String jsonString, T javaObject)
Decodes the given jsonString into the given target javaObject of type T.java.lang.String
encodeObject(java.lang.Object o)
Encodes given Java object into a JSON string, which is returned.void
encodeObject(java.lang.Object javaObject, java.io.OutputStream out)
Encodes given Java object into a JSON string, wirtten to out.
-
-
-
Constructor Detail
-
JSONCodec
public JSONCodec()
Constructor using the default configuration.
-
JSONCodec
public JSONCodec(JSONCodecConfiguration cfg)
Constructor using a specific configuration.- Parameters:
cfg
-JSONCodecConfiguration
to be used by the new JSONCodec.
-
-
Method Detail
-
decodeObject
public <T> T decodeObject(java.lang.String jsonString, T javaObject) throws JSONException
Decodes the given jsonString into the given target javaObject of type T.- Throws:
JSONException
-
decodeObject
public <T> T decodeObject(java.io.InputStream inputStream, T targetObject) throws JSONException
Decodes the given JSON string from input stream into the given target object of type T.- Throws:
JSONException
-
decodeObject
public <T> T decodeObject(java.io.InputStream inputStream, java.lang.Class<T> targetType) throws JSONException
Decodes the given JSON string from input stream into a Java object of the given target type T.- Throws:
JSONException
-
decodeObject
public <T> T decodeObject(java.lang.String jsonString, java.lang.Class<T> targetType) throws JSONException
Decodes the given JSON string into a Java object of the given target type T.- Throws:
JSONException
-
encodeObject
public java.lang.String encodeObject(java.lang.Object o) throws JSONException
Encodes given Java object into a JSON string, which is returned.- Throws:
JSONException
-
encodeObject
public void encodeObject(java.lang.Object javaObject, java.io.OutputStream out) throws JSONException
Encodes given Java object into a JSON string, wirtten to out.- Throws:
JSONException
-
-