Skip to content

java API annotated with gson annotations while jackson serializer is used #4221

@tipame

Description

@tipame

Describe the bug
All Kubernates Java API objects annonated with Gson annotation like @SerializedName and @JsonAdapter
At the same time io.kubernetes.client.util.Yaml uses SnakeYaml which in turn uses Jackson and do not respect gson annotations.
It somehow works only because most of the names in java representation are the same as names in json.
But not always!
I generated a java api for networking.istio.io/v1 (using instruction https://github.com/kubernetes-client/java/blob/master/docs/generate-model-from-third-party-resources.md)
And now i have isue with deserializing V1ServiceEntrySpec as it contains enum with differend names for java and json reperesentations:

@JsonAdapter(LocationEnum.Adapter.class)
  public enum LocationEnum {
    EXTERNAL("MESH_EXTERNAL"),

    INTERNAL("MESH_INTERNAL");
}
Unable to find enum value 'MESH_EXTERNAL' for enum class: io.istio.models.V1ServiceEntrySpec$LocationEnum
 in 'reader', line 15, column 13:
      location: MESH_EXTERNAL # Indicates this s ... 
                ^

	at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2ndStep(Constructor.java:283)
	at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.construct(Constructor.java:169)
	at org.yaml.snakeyaml.constructor.BaseConstructor.constructObjectNoCheck(BaseConstructor.java:265)
	at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:248)
	at io.kubernetes.client.util.Yaml$CustomConstructor.constructObject(Yaml.java:247)
	at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.newInstance(Constructor.java:295)
	at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2ndStep(Constructor.java:260)
	... 14 more
Caused by: org.yaml.snakeyaml.error.YAMLException: Unable to find enum value 'MESH_EXTERNAL' for enum class: io.istio.models.V1ServiceEntrySpec$LocationEnum
	at org.yaml.snakeyaml.constructor.Constructor$ConstructScalar.constructStandardJavaInstance(Constructor.java:481)
	at org.yaml.snakeyaml.constructor.Constructor$ConstructScalar.construct(Constructor.java:365)
	at org.yaml.snakeyaml.constructor.BaseConstructor.constructObjectNoCheck(BaseConstructor.java:265)
	at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:248)
	at io.kubernetes.client.util.Yaml$CustomConstructor.constructObject(Yaml.java:247)
	at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2ndStep(Constructor.java:261)
	... 20 more

Client Version
e.g. 23.0.0

Java Version
e.g. Java 17

To Reproduce
Change java representation name for any property annotated with @SerializedName and @JsonAdapter in any KubernetesObject and try to deserialize object from yaml:
V1ServiceEntry se = Yaml.loadAs(new File("dummy-service-entry.yaml"), V1ServiceEntry.class);

Expected behavior
All Kubernetes API objects should be annotated with jackson annotations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions