Class Serialization
- java.lang.Object
-
- io.fabric8.kubernetes.client.utils.Serialization
-
public class Serialization extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static io.fabric8.kubernetes.model.jackson.UnmatchedFieldTypeModule
UNMATCHED_FIELD_TYPE_MODULE
Deprecated.
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <T> String
asJson(T object)
Returns a JSON representation of the given object.static <T> String
asYaml(T object)
Returns a YAML representation of the given object.static void
clearYamlMapper()
Deprecated.to be removed in later versionsstatic <T> T
clone(T resource)
Create a copy of the resource via serialization.static com.fasterxml.jackson.databind.ObjectMapper
jsonMapper()
Deprecated.the static mapper should not be used directlystatic <T> T
unmarshal(InputStream is)
Deprecated.useKubernetesSerialization
insteadstatic <T> T
unmarshal(InputStream is, com.fasterxml.jackson.core.type.TypeReference<T> type)
Deprecated.static <T> T
unmarshal(InputStream is, Class<T> type)
Unmarshals anInputStream
.static <T> T
unmarshal(String str)
Deprecated.useKubernetesSerialization
insteadstatic <T> T
unmarshal(String str, Class<T> type)
Unmarshals aString
static com.fasterxml.jackson.databind.ObjectMapper
yamlMapper()
Deprecated.useasYaml(Object)
or one of the unmarshal methods
-
-
-
Field Detail
-
UNMATCHED_FIELD_TYPE_MODULE
@Deprecated public static final io.fabric8.kubernetes.model.jackson.UnmatchedFieldTypeModule UNMATCHED_FIELD_TYPE_MODULE
Deprecated.
-
-
Method Detail
-
jsonMapper
@Deprecated public static com.fasterxml.jackson.databind.ObjectMapper jsonMapper()
Deprecated.the static mapper should not be used directlyObjectMapper
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.useasYaml(Object)
or one of the unmarshal methodsObjectMapper
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 versionsAllow 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.useKubernetesSerialization
insteadUnmarshals a stream.The type is assumed to be
KubernetesResource
- Type Parameters:
T
- The target type.- Parameters:
is
- TheInputStream
.- Returns:
- returns de-serialized object
-
unmarshal
@Deprecated public static <T> T unmarshal(String str)
Deprecated.useKubernetesSerialization
insteadUnmarshals 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 static <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 static <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
-
unmarshal
@Deprecated public static <T> T unmarshal(InputStream is, com.fasterxml.jackson.core.type.TypeReference<T> type)
Deprecated.Unmarshals anInputStream
.- Type Parameters:
T
- Template argument denoting type- Parameters:
is
- TheInputStream
.type
- TheTypeReference
.- 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
-
-