Class KubernetesSerialization
- java.lang.Object
-
- io.fabric8.kubernetes.client.utils.KubernetesSerialization
-
public class KubernetesSerialization extends Object
-
-
Constructor Summary
Constructors Constructor Description KubernetesSerialization()Creates a new instance with a fresh ObjectMapperKubernetesSerialization(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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> StringasJson(T object)Returns a JSON representation of the given object.<T> StringasYaml(T object)Returns a YAML representation of the given object.<T> Tclone(T resource)Create a copy of the resource via serialization.protected voidconfigureMapper(com.fasterxml.jackson.databind.ObjectMapper mapper)TypeconstructParametricType(Class<?> parameterizedClass, Class<?>... parameterClasses)StringconvertToJson(String input)<T> TconvertValue(Object value, Class<T> type)Class<? extends io.fabric8.kubernetes.api.model.KubernetesResource>getRegisteredKubernetesResource(String apiVersion, String kind)io.fabric8.kubernetes.model.jackson.UnmatchedFieldTypeModulegetUnmatchedFieldTypeModule()voidregisterKubernetesResource(Class<? extends io.fabric8.kubernetes.api.model.KubernetesResource> clazz)Registers a new resource, which can then be recognized for deserializationvoidregisterKubernetesResource(String apiVersion, String kind, Class<? extends io.fabric8.kubernetes.api.model.KubernetesResource> clazz)Registers a new resource, which can then be recognized for deserialization.<T> Tunmarshal(InputStream is)Unmarshals a stream.<T> Tunmarshal(InputStream is, com.fasterxml.jackson.core.type.TypeReference<T> type)<T> Tunmarshal(InputStream is, Class<T> type)Unmarshals anInputStream.<T> Tunmarshal(String str)Unmarshals aString<T> Tunmarshal(String str, Class<T> type)Unmarshals aString
-
-
-
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:
searchClassloaders- ifKubernetesResourceshould be automatically discovered viaServiceLoader
-
-
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- TheInputStream.- 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 aStringThe type is assumed to be
KubernetesResource- Type Parameters:
T- template argument denoting type- Parameters:
str- TheString.- Returns:
- returns de-serialized object
-
unmarshal
public <T> T unmarshal(String str, Class<T> type)
Unmarshals aString- Type Parameters:
T- template argument denoting type- Parameters:
str- TheString.type- The target type.- Returns:
- returns de-serialized object
-
unmarshal
public <T> T unmarshal(InputStream is, Class<T> type)
Unmarshals anInputStream.- Type Parameters:
T- Template argument denoting type- Parameters:
is- TheInputStream.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:
IllegalArgumentException- if the cloning cannot be performed
-
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.
-
-