Package org.apache.wayang.core.util
Class JsonSerializables
- java.lang.Object
-
- org.apache.wayang.core.util.JsonSerializables
-
public class JsonSerializables extends java.lang.Object
Utility to deal withJsonSerializable
s.
-
-
Constructor Summary
Constructors Constructor Description JsonSerializables()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static WayangJsonObj
addClassTag(java.lang.Object obj, WayangJsonObj wayangJsonObj)
static WayangJsonObj
addClassTag(java.lang.Object obj, WayangJsonObj wayangJsonObj, boolean isAddClassTag)
static java.lang.Object
deserialize(java.lang.Object json)
Deserialize a given JSON datatype.static <T> T
deserialize(WayangJsonObj wayangJsonObj)
static <T> T
deserialize(WayangJsonObj wayangJsonObj, java.lang.Class<? extends T> cls)
Deserialize aWayangJsonObj
that should correspond to aJsonSerializable
.static <T> T
deserialize(WayangJsonObj wayangJsonObj, JsonSerializer<T> serializer)
static <T> T
deserialize(WayangJsonObj wayangJsonObj, JsonSerializer<T> serializer, java.lang.Class<? extends T> cls)
Deserialize aWayangJsonObj
with aJsonSerializer
.static <T> java.util.List<T>
deserializeAllAsList(WayangJsonArray wayangJsonArray)
Deserialize aWayangJsonArray
according to the rules ofdeserialize(Object)
.static <T> java.util.List<T>
deserializeAllAsList(WayangJsonArray wayangJsonArray, java.lang.Class<T> cls)
Deserialize aWayangJsonArray
according to the rules ofdeserialize(WayangJsonObj, Class)
.static <T> java.util.List<T>
deserializeAllAsList(WayangJsonArray wayangJsonArray, JsonSerializer<T> serializer)
Deserialize aWayangJsonArray
according to the rules ofdeserialize(WayangJsonObj, JsonSerializer)
.static <T> java.util.List<T>
deserializeAllAsList(WayangJsonArray wayangJsonArray, JsonSerializer<T> serializer, java.lang.Class<T> cls)
Deserialize aWayangJsonArray
according to the rules ofdeserialize(WayangJsonObj, JsonSerializer, Class)
.static java.lang.Class<?>
getClassTag(WayangJsonObj wayangJsonObj)
Read and load the specifiedClass
in aWayangJsonObj
.static boolean
isJsonCompatible(java.lang.Object obj)
Tells whether the given instance is a JSON datatype.static boolean
isJsonNull(java.lang.Object obj)
Tells whether the given instance is a (JSON)null
value.static boolean
isUnconvertedInstance(java.lang.Object obj)
Tells whether the given instance does not require conversion, which is the case forLong
s,Integer
s,Double
s,String
s, andnull
s.static java.lang.Object
serialize(java.lang.Object obj, boolean isPolymorph)
Try to serialize the givenObject
.static WayangJsonObj
serialize(JsonSerializable serializable, boolean isPolymorph)
Serialize the givenJsonSerializable
.static <T> WayangJsonObj
serialize(T obj, boolean isPolymorph, JsonSerializer<T> serializer)
Serialize the givenObject
using a specificJsonSerializer
.static WayangJsonArray
serializeAll(java.util.Collection<?> collection, boolean isPolymorph)
Try to serialize the givenObject
s.static <T> WayangJsonArray
serializeAll(java.util.Collection<T> collection, boolean isPolymorph, JsonSerializer<T> serializer)
Serialize the givenObject
s 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
- theObject
to serializeisPolymorph
- in case aWayangJsonObj
is created, whether it should be tagged with theClass
ofobj
- Returns:
- the serialization result
- See Also:
isJsonCompatible(Object)
-
serialize
public static WayangJsonObj serialize(JsonSerializable serializable, boolean isPolymorph)
Serialize the givenJsonSerializable
.- Parameters:
serializable
- theJsonSerializable
to serializeisPolymorph
- in case aWayangJsonObj
is created, whether it should be tagged with theClass
ofserializable
- Returns:
- the serialization result
-
serialize
public static <T> WayangJsonObj serialize(T obj, boolean isPolymorph, JsonSerializer<T> serializer)
Serialize the givenObject
using a specificJsonSerializer
.- Parameters:
obj
- theObject
to serializeisPolymorph
- in case aWayangJsonObj
is created, whether it should be tagged with theClass
ofserializable
serializer
- theJsonSerializer
- Returns:
- the serialization result
-
serializeAll
public static WayangJsonArray serializeAll(java.util.Collection<?> collection, boolean isPolymorph)
Try to serialize the givenObject
s. They must be JSON-compatible or aJsonSerializable
s.- Parameters:
collection
- theObject
s to serializeisPolymorph
- in case aWayangJsonObj
is created, whether it should be tagged with theClass
of 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 givenObject
s using a specificJsonSerializer
.- Parameters:
collection
- theObject
s to serializeisPolymorph
- in case aWayangJsonObj
is created, whether it should be tagged with theClass
ofserializable
serializer
- 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:json
is a (JSON)null
value;json
is a basic (JSON) datatype;json
is aClass
-taggedWayangJsonObj
that corresponds to aJsonSerializable
;json
is aWayangJsonArray
withClass
-taggedWayangJsonObj
s that correspond to aJsonSerializable
s - 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 aWayangJsonObj
that should correspond to aJsonSerializable
.- Parameters:
wayangJsonObj
- theWayangJsonObj
cls
- theClass
of the deserialization product- Returns:
- the deserialization product
-
deserialize
public static <T> T deserialize(WayangJsonObj wayangJsonObj, JsonSerializer<T> serializer)
- Parameters:
wayangJsonObj
- theWayangJsonObj
serializer
- theJsonSerializer
- Returns:
- the deserialization product
-
deserialize
public static <T> T deserialize(WayangJsonObj wayangJsonObj, JsonSerializer<T> serializer, java.lang.Class<? extends T> cls)
Deserialize aWayangJsonObj
with aJsonSerializer
.- Parameters:
wayangJsonObj
- theWayangJsonObj
serializer
- theJsonSerializer
cls
- theClass
of the deserialization product- Returns:
- the deserialization product
-
deserializeAllAsList
public static <T> java.util.List<T> deserializeAllAsList(WayangJsonArray wayangJsonArray)
Deserialize aWayangJsonArray
according 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 aWayangJsonArray
according to the rules ofdeserialize(WayangJsonObj, Class)
.- Parameters:
wayangJsonArray
- theWayangJsonArray
cls
- theClass
of the elements in thejsonArray
- Returns:
- the deserialization product
-
deserializeAllAsList
public static <T> java.util.List<T> deserializeAllAsList(WayangJsonArray wayangJsonArray, JsonSerializer<T> serializer)
Deserialize aWayangJsonArray
according to the rules ofdeserialize(WayangJsonObj, JsonSerializer)
.- Parameters:
wayangJsonArray
- theWayangJsonArray
serializer
- 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 aWayangJsonArray
according to the rules ofdeserialize(WayangJsonObj, JsonSerializer, Class)
.- Parameters:
wayangJsonArray
- theWayangJsonArray
serializer
- theJsonSerializer
cls
- theClass
of the elements in thejsonArray
- Returns:
- the deserialization product
-
addClassTag
public static WayangJsonObj addClassTag(java.lang.Object obj, WayangJsonObj wayangJsonObj)
- Parameters:
obj
- whoseClass
should be taggedwayangJsonObj
- that should be tagged- Returns:
- the
jsonObject
-
addClassTag
public static WayangJsonObj addClassTag(java.lang.Object obj, WayangJsonObj wayangJsonObj, boolean isAddClassTag)
- Parameters:
obj
- whoseClass
should 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 specifiedClass
in aWayangJsonObj
.- Parameters:
wayangJsonObj
- that contains theClass
tag- Returns:
- the loaded
Class
ornull
if none exists - Throws:
java.lang.ClassNotFoundException
- if theClass
could not be loaded
-
isJsonNull
public static boolean isJsonNull(java.lang.Object obj)
Tells whether the given instance is a (JSON)null
value.- Parameters:
obj
- the instance to test- Returns:
- whether
obj
is a (JSON)null
value
-
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
obj
is 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 forLong
s,Integer
s,Double
s,String
s, andnull
s.- Parameters:
obj
- the instance to test- Returns:
- whether
obj
does not require conversion
-
-