Class JsonSerializables


  • public class JsonSerializables
    extends java.lang.Object
    Utility to deal with JsonSerializables.
    • Constructor Detail

      • JsonSerializables

        public JsonSerializables()
    • Method Detail

      • serialize

        public static java.lang.Object serialize​(java.lang.Object obj,
                                                 boolean isPolymorph)
        Try to serialize the given Object. It must be JSON-compatible or a JsonSerializable.
        Parameters:
        obj - the Object to serialize
        isPolymorph - in case a WayangJsonObj is created, whether it should be tagged with the Class of obj
        Returns:
        the serialization result
        See Also:
        isJsonCompatible(Object)
      • serialize

        public static <T> WayangJsonObj serialize​(T obj,
                                                  boolean isPolymorph,
                                                  JsonSerializer<T> serializer)
        Serialize the given Object using a specific JsonSerializer.
        Parameters:
        obj - the Object to serialize
        isPolymorph - in case a WayangJsonObj is created, whether it should be tagged with the Class of serializable
        serializer - the JsonSerializer
        Returns:
        the serialization result
      • serializeAll

        public static WayangJsonArray serializeAll​(java.util.Collection<?> collection,
                                                   boolean isPolymorph)
        Try to serialize the given Objects. They must be JSON-compatible or a JsonSerializables.
        Parameters:
        collection - the Objects to serialize
        isPolymorph - in case a WayangJsonObj is created, whether it should be tagged with the Class of the according Object
        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 given Objects using a specific JsonSerializer.
        Parameters:
        collection - the Objects to serialize
        isPolymorph - in case a WayangJsonObj is created, whether it should be tagged with the Class of serializable
        serializer - the JsonSerializer
        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:
        Parameters:
        json - the JSON data
        Returns:
        the deserialization result
      • deserialize

        public static <T> T deserialize​(WayangJsonObj wayangJsonObj,
                                        java.lang.Class<? extends T> cls)
        Deserialize a WayangJsonObj that should correspond to a JsonSerializable.
        Parameters:
        wayangJsonObj - the WayangJsonObj
        cls - the Class of the deserialization product
        Returns:
        the deserialization product
      • addClassTag

        public static WayangJsonObj addClassTag​(java.lang.Object obj,
                                                WayangJsonObj wayangJsonObj)
        Tag the WayangJsonObj with the Class of the other Object.
        Parameters:
        obj - whose Class should be tagged
        wayangJsonObj - that should be tagged
        Returns:
        the jsonObject
      • addClassTag

        public static WayangJsonObj addClassTag​(java.lang.Object obj,
                                                WayangJsonObj wayangJsonObj,
                                                boolean isAddClassTag)
        Optionally tag the WayangJsonObj with the Class of the other Object.
        Parameters:
        obj - whose Class should be tagged
        wayangJsonObj - that should be tagged
        isAddClassTag - if this is false, 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 specified Class in a WayangJsonObj.
        Parameters:
        wayangJsonObj - that contains the Class tag
        Returns:
        the loaded Class or null if none exists
        Throws:
        java.lang.ClassNotFoundException - if the Class 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 for Longs, Integers, Doubles, Strings, and nulls.
        Parameters:
        obj - the instance to test
        Returns:
        whether obj does not require conversion