Class KubernetesSerialization


  • public class KubernetesSerialization
    extends Object
    • Constructor Detail

      • KubernetesSerialization

        public KubernetesSerialization()
        Creates a new instance with a fresh ObjectMapper
      • KubernetesSerialization

        public KubernetesSerialization​(com.fasterxml.jackson.databind.ObjectMapper mapper,
                                       boolean searchClassloaders)
        Creates a new instance with the given ObjectMapper, which will be configured for use for kubernetes resource serialization / deserialization.
        Parameters:
        mapper - the ObjectMapper to use.
        searchClassloaders - if KubernetesResource should be automatically discovered via ServiceLoader.
      • KubernetesSerialization

        public KubernetesSerialization​(com.fasterxml.jackson.databind.ObjectMapper mapper,
                                       boolean searchClassloaders,
                                       YamlDumpSettings yamlDumpSettings)
        Creates a new instance with the given ObjectMapper, which will be configured for use for kubernetes resource serialization / deserialization.
        Parameters:
        mapper - the ObjectMapper to use.
        searchClassloaders - if KubernetesResource should be automatically discovered via ServiceLoader.
        yamlDumpSettings - configuration for YAML serialization.
    • Method Detail

      • configureMapper

        protected void configureMapper​(com.fasterxml.jackson.databind.ObjectMapper mapper)
      • asJson

        public <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 <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

        public <T> T unmarshal​(InputStream is)
        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

        public <T> T unmarshal​(InputStream is,
                               com.fasterxml.jackson.core.type.TypeReference<T> type)
      • unmarshal

        public <T> T unmarshal​(String str)
        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 <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 <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 <T> T clone​(T resource)
        Create a copy of the resource via serialization.
        Returns:
        a deep clone of the resource
        Throws:
        IllegalStateException - if the cloning cannot be performed
      • convertValue

        public <T> T convertValue​(Object value,
                                  Class<T> type)
      • constructParametricType

        public Type constructParametricType​(Class<?> parameterizedClass,
                                            Class<?>... parameterClasses)
      • getRegisteredKubernetesResource

        public Class<? extends io.fabric8.kubernetes.api.model.KubernetesResource> getRegisteredKubernetesResource​(String apiVersion,
                                                                                                                   String kind)
      • getUnmatchedFieldTypeModule

        public io.fabric8.kubernetes.model.jackson.UnmatchedFieldTypeModule getUnmatchedFieldTypeModule()
      • registerKubernetesResource

        public void registerKubernetesResource​(Class<? extends io.fabric8.kubernetes.api.model.KubernetesResource> clazz)
        Registers a new resource, which can then be recognized for deserialization
      • registerKubernetesResource

        public void registerKubernetesResource​(String apiVersion,
                                               String kind,
                                               Class<? extends io.fabric8.kubernetes.api.model.KubernetesResource> clazz)
        Registers a new resource, which can then be recognized for deserialization.

        This is for advanced usage scenarios where you have a class that lacks annotations, or you can have the same class represent multiple versions or groups. However the DSL won't work with those classes - the resource(Class) method and other DSL logic only consults annotations via static HasMetadata methods.

      • convertToJson

        public String convertToJson​(String input)