public class Serialization
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static Serialization |
create(SerializerIds idLookup,
SerializationPolicy policy)
Create a new instance of
Serialization with the specified IDs and policy. |
DsonJavaType |
dsonCollectionType(java.lang.Class<? extends java.util.Collection> collectionClass,
java.lang.Class<?> elementClass)
Return a collection type for use with the
fromDson(byte[], DsonJavaType) method. |
<T> T |
fromDson(byte[] bytes,
java.lang.Class<T> valueType)
Convert the specified DSON encoded byte array to an instance of the
specified class.
|
<T> T |
fromDson(byte[] bytes,
DsonJavaType valueType)
Convert the specified DSON encoded byte array to an instance of the
specified class.
|
<T> T |
fromJson(java.lang.String json,
java.lang.Class<T> valueType)
Convert the specified JSON encoded string to an instance of the
specified class.
|
<T> T |
fromJson(java.lang.String json,
JsonJavaType valueType)
Convert the specified JSON encoded string to an instance of the
specified class.
|
<T> T |
fromJsonObject(org.json.JSONObject json,
java.lang.Class<T> valueType)
Convert the specified JSONObject to an instance of the
specified class.
|
java.lang.Class<?> |
getClassForId(java.lang.String id)
Retrieve class given a serializer ID.
|
java.lang.String |
getIdForClass(java.lang.Class<?> cls)
Retrieve serializer ID from class.
|
JsonJavaType |
jsonCollectionType(java.lang.Class<? extends java.util.Collection> collectionClass,
java.lang.Class<?> elementClass)
Return a collection type for use with the
fromJson(String, JsonJavaType) method. |
byte[] |
toDson(java.lang.Object o,
DsonOutput.Output output)
Convert the specified object to DSON encoded bytes for the specified
output mode.
|
java.lang.String |
toJson(java.lang.Object o,
DsonOutput.Output output)
Convert the specified object to a JSON encoded string for the specified
output mode.
|
org.json.JSONObject |
toJsonObject(java.lang.Object o,
DsonOutput.Output output)
Convert the specified object to a
JSONObject encoded string for the specified
output mode. |
public static Serialization create(SerializerIds idLookup, SerializationPolicy policy)
Serialization
with the specified IDs and policy.idLookup
- The SerializerIds
to use for class and property lookup.policy
- The SerializationPolicy
to use for determining serialization outputs.Serialization
.public byte[] toDson(java.lang.Object o, DsonOutput.Output output) throws SerializationException
o
- The object to serializeoutput
- The output mode to serialize forSerializationException
- if something goes wrong with serializationpublic java.lang.String toJson(java.lang.Object o, DsonOutput.Output output) throws SerializationException
o
- The object to serializeoutput
- The output mode to serialize forSerializationException
- if something goes wrong with serializationpublic org.json.JSONObject toJsonObject(java.lang.Object o, DsonOutput.Output output)
JSONObject
encoded string for the specified
output mode.o
- The object to serializeoutput
- The output mode to serialize forpublic <T> T fromDson(byte[] bytes, java.lang.Class<T> valueType) throws SerializationException
bytes
- The DSON encoded object to deserializevalueType
- The class of the object to deserializeSerializationException
- if something goes wrong with serializationpublic <T> T fromDson(byte[] bytes, DsonJavaType valueType) throws SerializationException
bytes
- The DSON encoded object to deserializevalueType
- The class of the object to deserializeSerializationException
- if something goes wrong with serializationpublic <T> T fromJson(java.lang.String json, java.lang.Class<T> valueType) throws SerializationException
json
- The JSON encoded object to deserializevalueType
- The class of the object to deserializeSerializationException
- if something goes wrong with serializationpublic <T> T fromJson(java.lang.String json, JsonJavaType valueType) throws SerializationException
json
- The JSON encoded object to deserializevalueType
- The class of the object to deserializeSerializationException
- if something goes wrong with serializationpublic <T> T fromJsonObject(org.json.JSONObject json, java.lang.Class<T> valueType)
json
- The JSONObject
object to convertvalueType
- The class of the object to convert topublic DsonJavaType dsonCollectionType(java.lang.Class<? extends java.util.Collection> collectionClass, java.lang.Class<?> elementClass)
fromDson(byte[], DsonJavaType)
method.collectionClass
- The collection class to deserialize.elementClass
- The collection element type.public JsonJavaType jsonCollectionType(java.lang.Class<? extends java.util.Collection> collectionClass, java.lang.Class<?> elementClass)
fromJson(String, JsonJavaType)
method.collectionClass
- The collection class to deserialize.elementClass
- The collection element type.public java.lang.String getIdForClass(java.lang.Class<?> cls)
cls
- The class to look up the ID fornull
if no serializer for the specified class.public java.lang.Class<?> getClassForId(java.lang.String id)
id
- The ID to look up the class fornull
if serializer ID unknown.