Class Serialization


  • public class Serialization
    extends Object
    • Method Detail

      • jsonMapper

        @Deprecated
        public static com.fasterxml.jackson.databind.ObjectMapper jsonMapper()
        Deprecated.
        the static mapper should not be used directly
        ObjectMapper singleton instance used internally by the Kubernetes client.

        The ObjectMapper has an UnmatchedFieldTypeModule module registered. This module allows the client to work with Resources that contain properties that don't match the target field type. This is especially useful and necessary to work with OpenShift Templates.

        n.b. the use of this module gives precedence to properties present in the additionalProperties Map present in most KubernetesResource instances. If a property is both defined in the Map and in the original field, the one from the additionalProperties Map will be serialized.

      • yamlMapper

        @Deprecated
        public static com.fasterxml.jackson.databind.ObjectMapper yamlMapper()
        Deprecated.
        use asYaml(Object) or one of the unmarshal methods
        ObjectMapper singleton instance used internally by the Kubernetes client.

        The ObjectMapper has an UnmatchedFieldTypeModule module registered. This module allows the client to work with Resources that contain properties that don't match the target field type. This is especially useful and necessary to work with OpenShift Templates.

        n.b. the use of this module gives precedence to properties present in the additionalProperties Map present in most KubernetesResource instances. If a property is both defined in the Map and in the original field, the one from the additionalProperties Map will be serialized.

      • clearYamlMapper

        @Deprecated
        public static void clearYamlMapper()
        Deprecated.
        to be removed in later versions
        Allow application to clear out the YAML mapper in order to allow its garbage collection. This is useful because in a lot of cases the YAML mapper is only need at application startup when the client is created, so there is no reason to keep the very heavy (in terms of memory) mapper around indefinitely.
      • asJson

        public static <T> String asJson​(T object)
        Returns a JSON representation of the given object.

        If the provided object contains a JsonAnyGetter annotated method with a Map that contains an entry that overrides a field of the provided object, the Map entry will take precedence upon serialization. Properties won't be duplicated.

        Type Parameters:
        T - the type of the object being serialized.
        Parameters:
        object - the object to serialize.
        Returns:
        a String containing a JSON representation of the provided object.
      • asYaml

        public static <T> String asYaml​(T object)
        Returns a YAML representation of the given object.

        If the provided object contains a JsonAnyGetter annotated method with a Map that contains an entry that overrides a field of the provided object, the Map entry will take precedence upon serialization. Properties won't be duplicated.

        Type Parameters:
        T - the type of the object being serialized.
        Parameters:
        object - the object to serialize.
        Returns:
        a String containing a JSON representation of the provided object.
      • unmarshal

        @Deprecated
        public static <T> T unmarshal​(InputStream is)
        Deprecated.
        Unmarshals a stream.

        The type is assumed to be KubernetesResource

        Type Parameters:
        T - The target type.
        Parameters:
        is - The InputStream.
        Returns:
        returns de-serialized object
      • unmarshal

        @Deprecated
        public static <T> T unmarshal​(String str)
        Deprecated.
        Unmarshals a String

        The type is assumed to be KubernetesResource

        Type Parameters:
        T - template argument denoting type
        Parameters:
        str - The String.
        Returns:
        returns de-serialized object
      • unmarshal

        public static <T> T unmarshal​(String str,
                                      Class<T> type)
        Unmarshals a String
        Type Parameters:
        T - template argument denoting type
        Parameters:
        str - The String.
        type - The target type.
        Returns:
        returns de-serialized object
      • unmarshal

        public static <T> T unmarshal​(InputStream is,
                                      Class<T> type)
        Unmarshals an InputStream.
        Type Parameters:
        T - Template argument denoting type
        Parameters:
        is - The InputStream.
        type - The type.
        Returns:
        returns de-serialized object
      • clone

        public static <T> T clone​(T resource)
        Create a copy of the resource via serialization.
        Returns:
        a deep clone of the resource
        Throws:
        IllegalArgumentException - if the cloning cannot be performed