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> String
asJson(T object)
Returns a JSON representation of the given object.<T> String
asYaml(T object)
Returns a YAML representation of the given object.<T> T
clone(T resource)
Create a copy of the resource via serialization.protected void
configureMapper(com.fasterxml.jackson.databind.ObjectMapper mapper)
Type
constructParametricType(Class<?> parameterizedClass, Class<?>... parameterClasses)
String
convertToJson(String input)
<T> T
convertValue(Object value, Class<T> type)
Class<? extends io.fabric8.kubernetes.api.model.KubernetesResource>
getRegisteredKubernetesResource(String apiVersion, String kind)
io.fabric8.kubernetes.model.jackson.UnmatchedFieldTypeModule
getUnmatchedFieldTypeModule()
void
registerKubernetesResource(Class<? extends io.fabric8.kubernetes.api.model.KubernetesResource> clazz)
Registers a new resource, which can then be recognized for deserializationvoid
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.<T> T
unmarshal(InputStream is)
Unmarshals a stream.<T> T
unmarshal(InputStream is, com.fasterxml.jackson.core.type.TypeReference<T> type)
<T> T
unmarshal(InputStream is, Class<T> type)
Unmarshals anInputStream
.<T> T
unmarshal(String str)
Unmarshals aString
<T> T
unmarshal(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
- ifKubernetesResource
should 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 aString
The 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.
-
-