Package org.apache.wayang.core.util
Class JsonSerializables
- java.lang.Object
-
- org.apache.wayang.core.util.JsonSerializables
-
public class JsonSerializables extends java.lang.ObjectUtility to deal withJsonSerializables.
-
-
Constructor Summary
Constructors Constructor Description JsonSerializables()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static WayangJsonObjaddClassTag(java.lang.Object obj, WayangJsonObj wayangJsonObj)static WayangJsonObjaddClassTag(java.lang.Object obj, WayangJsonObj wayangJsonObj, boolean isAddClassTag)static java.lang.Objectdeserialize(java.lang.Object json)Deserialize a given JSON datatype.static <T> Tdeserialize(WayangJsonObj wayangJsonObj)static <T> Tdeserialize(WayangJsonObj wayangJsonObj, java.lang.Class<? extends T> cls)Deserialize aWayangJsonObjthat should correspond to aJsonSerializable.static <T> Tdeserialize(WayangJsonObj wayangJsonObj, JsonSerializer<T> serializer)static <T> Tdeserialize(WayangJsonObj wayangJsonObj, JsonSerializer<T> serializer, java.lang.Class<? extends T> cls)Deserialize aWayangJsonObjwith aJsonSerializer.static <T> java.util.List<T>deserializeAllAsList(WayangJsonArray wayangJsonArray)Deserialize aWayangJsonArrayaccording to the rules ofdeserialize(Object).static <T> java.util.List<T>deserializeAllAsList(WayangJsonArray wayangJsonArray, java.lang.Class<T> cls)Deserialize aWayangJsonArrayaccording to the rules ofdeserialize(WayangJsonObj, Class).static <T> java.util.List<T>deserializeAllAsList(WayangJsonArray wayangJsonArray, JsonSerializer<T> serializer)Deserialize aWayangJsonArrayaccording to the rules ofdeserialize(WayangJsonObj, JsonSerializer).static <T> java.util.List<T>deserializeAllAsList(WayangJsonArray wayangJsonArray, JsonSerializer<T> serializer, java.lang.Class<T> cls)Deserialize aWayangJsonArrayaccording to the rules ofdeserialize(WayangJsonObj, JsonSerializer, Class).static java.lang.Class<?>getClassTag(WayangJsonObj wayangJsonObj)Read and load the specifiedClassin aWayangJsonObj.static booleanisJsonCompatible(java.lang.Object obj)Tells whether the given instance is a JSON datatype.static booleanisJsonNull(java.lang.Object obj)Tells whether the given instance is a (JSON)nullvalue.static booleanisUnconvertedInstance(java.lang.Object obj)Tells whether the given instance does not require conversion, which is the case forLongs,Integers,Doubles,Strings, andnulls.static java.lang.Objectserialize(java.lang.Object obj, boolean isPolymorph)Try to serialize the givenObject.static WayangJsonObjserialize(JsonSerializable serializable, boolean isPolymorph)Serialize the givenJsonSerializable.static <T> WayangJsonObjserialize(T obj, boolean isPolymorph, JsonSerializer<T> serializer)Serialize the givenObjectusing a specificJsonSerializer.static WayangJsonArrayserializeAll(java.util.Collection<?> collection, boolean isPolymorph)Try to serialize the givenObjects.static <T> WayangJsonArrayserializeAll(java.util.Collection<T> collection, boolean isPolymorph, JsonSerializer<T> serializer)Serialize the givenObjects using a specificJsonSerializer.
-
-
-
Method Detail
-
serialize
public static java.lang.Object serialize(java.lang.Object obj, boolean isPolymorph)Try to serialize the givenObject. It must be JSON-compatible or aJsonSerializable.- Parameters:
obj- theObjectto serializeisPolymorph- in case aWayangJsonObjis created, whether it should be tagged with theClassofobj- Returns:
- the serialization result
- See Also:
isJsonCompatible(Object)
-
serialize
public static WayangJsonObj serialize(JsonSerializable serializable, boolean isPolymorph)
Serialize the givenJsonSerializable.- Parameters:
serializable- theJsonSerializableto serializeisPolymorph- in case aWayangJsonObjis created, whether it should be tagged with theClassofserializable- Returns:
- the serialization result
-
serialize
public static <T> WayangJsonObj serialize(T obj, boolean isPolymorph, JsonSerializer<T> serializer)
Serialize the givenObjectusing a specificJsonSerializer.- Parameters:
obj- theObjectto serializeisPolymorph- in case aWayangJsonObjis created, whether it should be tagged with theClassofserializableserializer- theJsonSerializer- Returns:
- the serialization result
-
serializeAll
public static WayangJsonArray serializeAll(java.util.Collection<?> collection, boolean isPolymorph)
Try to serialize the givenObjects. They must be JSON-compatible or aJsonSerializables.- Parameters:
collection- theObjects to serializeisPolymorph- in case aWayangJsonObjis created, whether it should be tagged with theClassof the accordingObject- Returns:
- the serialization result
- See Also:
isJsonCompatible(Object)
-
serializeAll
public static <T> WayangJsonArray serializeAll(java.util.Collection<T> collection, boolean isPolymorph, JsonSerializer<T> serializer)
Serialize the givenObjects using a specificJsonSerializer.- Parameters:
collection- theObjects to serializeisPolymorph- in case aWayangJsonObjis created, whether it should be tagged with theClassofserializableserializer- theJsonSerializer- Returns:
- the serialization result
-
deserialize
public static java.lang.Object deserialize(java.lang.Object json)
Deserialize a given JSON datatype. The following cases are supported:jsonis a (JSON)nullvalue;jsonis a basic (JSON) datatype;jsonis aClass-taggedWayangJsonObjthat corresponds to aJsonSerializable;jsonis aWayangJsonArraywithClass-taggedWayangJsonObjs that correspond to aJsonSerializables - in this case, the result type is aList.
- Parameters:
json- the JSON data- Returns:
- the deserialization result
-
deserialize
public static <T> T deserialize(WayangJsonObj wayangJsonObj)
- Parameters:
wayangJsonObj- theWayangJsonObj- Returns:
- the deserialization product
-
deserialize
public static <T> T deserialize(WayangJsonObj wayangJsonObj, java.lang.Class<? extends T> cls)
Deserialize aWayangJsonObjthat should correspond to aJsonSerializable.- Parameters:
wayangJsonObj- theWayangJsonObjcls- theClassof the deserialization product- Returns:
- the deserialization product
-
deserialize
public static <T> T deserialize(WayangJsonObj wayangJsonObj, JsonSerializer<T> serializer)
- Parameters:
wayangJsonObj- theWayangJsonObjserializer- theJsonSerializer- Returns:
- the deserialization product
-
deserialize
public static <T> T deserialize(WayangJsonObj wayangJsonObj, JsonSerializer<T> serializer, java.lang.Class<? extends T> cls)
Deserialize aWayangJsonObjwith aJsonSerializer.- Parameters:
wayangJsonObj- theWayangJsonObjserializer- theJsonSerializercls- theClassof the deserialization product- Returns:
- the deserialization product
-
deserializeAllAsList
public static <T> java.util.List<T> deserializeAllAsList(WayangJsonArray wayangJsonArray)
Deserialize aWayangJsonArrayaccording to the rules ofdeserialize(Object).- Parameters:
wayangJsonArray- theWayangJsonArray- Returns:
- the deserialization product
-
deserializeAllAsList
public static <T> java.util.List<T> deserializeAllAsList(WayangJsonArray wayangJsonArray, java.lang.Class<T> cls)
Deserialize aWayangJsonArrayaccording to the rules ofdeserialize(WayangJsonObj, Class).- Parameters:
wayangJsonArray- theWayangJsonArraycls- theClassof the elements in thejsonArray- Returns:
- the deserialization product
-
deserializeAllAsList
public static <T> java.util.List<T> deserializeAllAsList(WayangJsonArray wayangJsonArray, JsonSerializer<T> serializer)
Deserialize aWayangJsonArrayaccording to the rules ofdeserialize(WayangJsonObj, JsonSerializer).- Parameters:
wayangJsonArray- theWayangJsonArrayserializer- theJsonSerializer- Returns:
- the deserialization product
-
deserializeAllAsList
public static <T> java.util.List<T> deserializeAllAsList(WayangJsonArray wayangJsonArray, JsonSerializer<T> serializer, java.lang.Class<T> cls)
Deserialize aWayangJsonArrayaccording to the rules ofdeserialize(WayangJsonObj, JsonSerializer, Class).- Parameters:
wayangJsonArray- theWayangJsonArrayserializer- theJsonSerializercls- theClassof the elements in thejsonArray- Returns:
- the deserialization product
-
addClassTag
public static WayangJsonObj addClassTag(java.lang.Object obj, WayangJsonObj wayangJsonObj)
- Parameters:
obj- whoseClassshould be taggedwayangJsonObj- that should be tagged- Returns:
- the
jsonObject
-
addClassTag
public static WayangJsonObj addClassTag(java.lang.Object obj, WayangJsonObj wayangJsonObj, boolean isAddClassTag)
- Parameters:
obj- whoseClassshould be taggedwayangJsonObj- that should be taggedisAddClassTag- if this isfalse, no action will be performed- Returns:
- the
jsonObject
-
getClassTag
public static java.lang.Class<?> getClassTag(WayangJsonObj wayangJsonObj) throws java.lang.ClassNotFoundException
Read and load the specifiedClassin aWayangJsonObj.- Parameters:
wayangJsonObj- that contains theClasstag- Returns:
- the loaded
Classornullif none exists - Throws:
java.lang.ClassNotFoundException- if theClasscould not be loaded
-
isJsonNull
public static boolean isJsonNull(java.lang.Object obj)
Tells whether the given instance is a (JSON)nullvalue.- Parameters:
obj- the instance to test- Returns:
- whether
objis a (JSON)nullvalue
-
isJsonCompatible
public static boolean isJsonCompatible(java.lang.Object obj)
Tells whether the given instance is a JSON datatype.- Parameters:
obj- the instance to test- Returns:
- whether
objis a JSON datatype
-
isUnconvertedInstance
public static boolean isUnconvertedInstance(java.lang.Object obj)
Tells whether the given instance does not require conversion, which is the case forLongs,Integers,Doubles,Strings, andnulls.- Parameters:
obj- the instance to test- Returns:
- whether
objdoes not require conversion
-
-