Package org.apache.wayang.core.util
Class JsonSerializables
java.lang.Object
org.apache.wayang.core.util.JsonSerializables
Utility to deal with
JsonSerializable
s.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic WayangJsonObj
addClassTag
(Object obj, WayangJsonObj wayangJsonObj) static WayangJsonObj
addClassTag
(Object obj, WayangJsonObj wayangJsonObj, boolean isAddClassTag) static Object
deserialize
(Object json) Deserialize a given JSON datatype.static <T> T
deserialize
(WayangJsonObj wayangJsonObj) static <T> T
deserialize
(WayangJsonObj wayangJsonObj, 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, Class<? extends T> cls) Deserialize aWayangJsonObj
with aJsonSerializer
.static <T> List<T>
deserializeAllAsList
(WayangJsonArray wayangJsonArray) Deserialize aWayangJsonArray
according to the rules ofdeserialize(Object)
.static <T> List<T>
deserializeAllAsList
(WayangJsonArray wayangJsonArray, Class<T> cls) Deserialize aWayangJsonArray
according to the rules ofdeserialize(WayangJsonObj, Class)
.static <T> List<T>
deserializeAllAsList
(WayangJsonArray wayangJsonArray, JsonSerializer<T> serializer) Deserialize aWayangJsonArray
according to the rules ofdeserialize(WayangJsonObj, JsonSerializer)
.static <T> List<T>
deserializeAllAsList
(WayangJsonArray wayangJsonArray, JsonSerializer<T> serializer, Class<T> cls) Deserialize aWayangJsonArray
according to the rules ofdeserialize(WayangJsonObj, JsonSerializer, Class)
.static Class<?>
getClassTag
(WayangJsonObj wayangJsonObj) Read and load the specifiedClass
in aWayangJsonObj
.static boolean
isJsonCompatible
(Object obj) Tells whether the given instance is a JSON datatype.static boolean
isJsonNull
(Object obj) Tells whether the given instance is a (JSON)null
value.static boolean
static Object
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
(Collection<?> collection, boolean isPolymorph) Try to serialize the givenObject
s.static <T> WayangJsonArray
serializeAll
(Collection<T> collection, boolean isPolymorph, JsonSerializer<T> serializer) Serialize the givenObject
s 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
- theObject
to serializeisPolymorph
- in case aWayangJsonObj
is created, whether it should be tagged with theClass
ofobj
- Returns:
- the serialization result
- See Also:
-
serialize
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
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
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:
-
serializeAll
public static <T> WayangJsonArray serializeAll(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
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
- Parameters:
wayangJsonObj
- theWayangJsonObj
- Returns:
- the deserialization product
-
deserialize
Deserialize aWayangJsonObj
that should correspond to aJsonSerializable
.- Parameters:
wayangJsonObj
- theWayangJsonObj
cls
- theClass
of the deserialization product- Returns:
- the deserialization product
-
deserialize
- Parameters:
wayangJsonObj
- theWayangJsonObj
serializer
- theJsonSerializer
- Returns:
- the deserialization product
-
deserialize
public static <T> T deserialize(WayangJsonObj wayangJsonObj, JsonSerializer<T> serializer, Class<? extends T> cls) Deserialize aWayangJsonObj
with aJsonSerializer
.- Parameters:
wayangJsonObj
- theWayangJsonObj
serializer
- theJsonSerializer
cls
- theClass
of the deserialization product- Returns:
- the deserialization product
-
deserializeAllAsList
Deserialize aWayangJsonArray
according to the rules ofdeserialize(Object)
.- Parameters:
wayangJsonArray
- theWayangJsonArray
- Returns:
- the deserialization product
-
deserializeAllAsList
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> 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> List<T> deserializeAllAsList(WayangJsonArray wayangJsonArray, JsonSerializer<T> serializer, 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
- Parameters:
obj
- whoseClass
should be taggedwayangJsonObj
- that should be tagged- Returns:
- the
jsonObject
-
addClassTag
public static WayangJsonObj addClassTag(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
Read and load the specifiedClass
in aWayangJsonObj
.- Parameters:
wayangJsonObj
- that contains theClass
tag- Returns:
- the loaded
Class
ornull
if none exists - Throws:
ClassNotFoundException
- if theClass
could not be loaded
-
isJsonNull
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
Tells whether the given instance is a JSON datatype.- Parameters:
obj
- the instance to test- Returns:
- whether
obj
is a JSON datatype
-
isUnconvertedInstance
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
-