Package org.apache.wayang.core.util
Class JsonSerializables
java.lang.Object
org.apache.wayang.core.util.JsonSerializables
Utility to deal with
JsonSerializables.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic WayangJsonObjaddClassTag(Object obj, WayangJsonObj wayangJsonObj) static WayangJsonObjaddClassTag(Object obj, WayangJsonObj wayangJsonObj, boolean isAddClassTag) static Objectdeserialize(Object json) Deserialize a given JSON datatype.static <T> Tdeserialize(WayangJsonObj wayangJsonObj) static <T> Tdeserialize(WayangJsonObj wayangJsonObj, 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, Class<? extends T> cls) Deserialize aWayangJsonObjwith aJsonSerializer.static <T> List<T>deserializeAllAsList(WayangJsonArray wayangJsonArray) Deserialize aWayangJsonArrayaccording to the rules ofdeserialize(Object).static <T> List<T>deserializeAllAsList(WayangJsonArray wayangJsonArray, Class<T> cls) Deserialize aWayangJsonArrayaccording to the rules ofdeserialize(WayangJsonObj, Class).static <T> List<T>deserializeAllAsList(WayangJsonArray wayangJsonArray, JsonSerializer<T> serializer) Deserialize aWayangJsonArrayaccording to the rules ofdeserialize(WayangJsonObj, JsonSerializer).static <T> List<T>deserializeAllAsList(WayangJsonArray wayangJsonArray, JsonSerializer<T> serializer, Class<T> cls) Deserialize aWayangJsonArrayaccording to the rules ofdeserialize(WayangJsonObj, JsonSerializer, Class).static Class<?>getClassTag(WayangJsonObj wayangJsonObj) Read and load the specifiedClassin aWayangJsonObj.static booleanisJsonCompatible(Object obj) Tells whether the given instance is a JSON datatype.static booleanisJsonNull(Object obj) Tells whether the given instance is a (JSON)nullvalue.static booleanstatic ObjectTry 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(Collection<?> collection, boolean isPolymorph) Try to serialize the givenObjects.static <T> WayangJsonArrayserializeAll(Collection<T> collection, boolean isPolymorph, JsonSerializer<T> serializer) Serialize the givenObjects using a specificJsonSerializer.
-
Constructor Details
-
JsonSerializables
public JsonSerializables()
-
-
Method Details
-
serialize
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:
-
serialize
Serialize the givenJsonSerializable.- Parameters:
serializable- theJsonSerializableto serializeisPolymorph- in case aWayangJsonObjis created, whether it should be tagged with theClassofserializable- Returns:
- the serialization result
-
serialize
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
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:
-
serializeAll
public static <T> WayangJsonArray serializeAll(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
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
- Parameters:
wayangJsonObj- theWayangJsonObj- Returns:
- the deserialization product
-
deserialize
Deserialize aWayangJsonObjthat should correspond to aJsonSerializable.- Parameters:
wayangJsonObj- theWayangJsonObjcls- theClassof the deserialization product- Returns:
- the deserialization product
-
deserialize
- Parameters:
wayangJsonObj- theWayangJsonObjserializer- theJsonSerializer- Returns:
- the deserialization product
-
deserialize
public static <T> T deserialize(WayangJsonObj wayangJsonObj, JsonSerializer<T> serializer, Class<? extends T> cls) Deserialize aWayangJsonObjwith aJsonSerializer.- Parameters:
wayangJsonObj- theWayangJsonObjserializer- theJsonSerializercls- theClassof the deserialization product- Returns:
- the deserialization product
-
deserializeAllAsList
Deserialize aWayangJsonArrayaccording to the rules ofdeserialize(Object).- Parameters:
wayangJsonArray- theWayangJsonArray- Returns:
- the deserialization product
-
deserializeAllAsList
Deserialize aWayangJsonArrayaccording to the rules ofdeserialize(WayangJsonObj, Class).- Parameters:
wayangJsonArray- theWayangJsonArraycls- theClassof the elements in thejsonArray- Returns:
- the deserialization product
-
deserializeAllAsList
public static <T> 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> List<T> deserializeAllAsList(WayangJsonArray wayangJsonArray, JsonSerializer<T> serializer, 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
- Parameters:
obj- whoseClassshould be taggedwayangJsonObj- that should be tagged- Returns:
- the
jsonObject
-
addClassTag
public static WayangJsonObj addClassTag(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
Read and load the specifiedClassin aWayangJsonObj.- Parameters:
wayangJsonObj- that contains theClasstag- Returns:
- the loaded
Classornullif none exists - Throws:
ClassNotFoundException- if theClasscould not be loaded
-
isJsonNull
Tells whether the given instance is a (JSON)nullvalue.- Parameters:
obj- the instance to test- Returns:
- whether
objis a (JSON)nullvalue
-
isJsonCompatible
Tells whether the given instance is a JSON datatype.- Parameters:
obj- the instance to test- Returns:
- whether
objis a JSON datatype
-
isUnconvertedInstance
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
-