Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassCastException when using a default empty array in CRD #4584

Closed
tomverelst opened this issue Nov 18, 2022 · 4 comments
Closed

ClassCastException when using a default empty array in CRD #4584

tomverelst opened this issue Nov 18, 2022 · 4 comments

Comments

@tomverelst
Copy link

tomverelst commented Nov 18, 2022

Describe the bug

I have a CRD that has an array property in the spec that defaults to [].

foo:
  default: []
  items:
    properties:
      bar:
        type: string
    required:
      - bar
    type: object
type: array

I generate my Java classes using the io.fabric8:java-generator-maven-plugin:6.2.0 plugin (with generator-annotations). This results in the following generated code in my custom resource's Spec class:

    @com.fasterxml.jackson.annotation.JsonProperty("foo")
    @com.fasterxml.jackson.annotation.JsonSetter(nulls = com.fasterxml.jackson.annotation.Nulls.SKIP)
    private java.util.List<Foo> foo = io.fabric8.kubernetes.client.utils.Serialization.unmarshal("[]", java.util.List.class);;

When I attempt to initiate the spec class, it throws the following exception:

Caused by: java.lang.ClassCastException: class java.util.ArrayList cannot be cast to class java.util.Map (java.util.ArrayList and java.util.Map are in module java.base of loader 'bootstrap')
at io.fabric8.kubernetes.client.utils.Serialization.unmarshal(Serialization.java:237)

This error disappears when I remove the default: [] property from the array property.

Fabric8 Kubernetes Client version

6.2.0

Steps to reproduce

Run the following code:

io.fabric8.kubernetes.client.utils.Serialization.unmarshal("[]", java.util.List.class);

Expected behavior

Expect to have an ArrayList to be returned from the function call

Runtime

other (please specify in additional context)

Kubernetes API Server version

other (please specify in additional context)

Environment

macOS

Fabric8 Kubernetes Client Logs

java.lang.ClassCastException: class java.util.ArrayList cannot be cast to class java.util.Map (java.util.ArrayList and java.util.Map are in module java.base of loader 'bootstrap')
	at io.fabric8.kubernetes.client.utils.Serialization.unmarshal(Serialization.java:237)
	at io.fabric8.kubernetes.client.utils.Serialization.unmarshal(Serialization.java:351)
	at io.fabric8.kubernetes.client.utils.Serialization.unmarshal(Serialization.java:287)
	at io.fabric8.kubernetes.client.utils.Serialization.unmarshal(Serialization.java:272)

Additional context

No response

@shawkins
Copy link
Contributor

Should be addressed by #4533

@tomverelst
Copy link
Author

Should be addressed by #4533

Aha, cheers, did search for similar issues but did not find that one!

@andreaTP
Copy link
Member

@tomverelst we already fixed this, can you try to use the snapshot release and see if that solves your issues?

@tomverelst
Copy link
Author

Tested it and verified it works 👍 @andreaTP

Thanks all, closing this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants