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

Additional Attributes are generated to be ignored, because of wrong setting of JsonAnySetter annotation #4543

Closed
mteubner opened this issue Oct 31, 2022 · 3 comments · Fixed by #4561

Comments

@mteubner
Copy link

Describe the bug

Component : java-generator

The generation of additionalProperties out of a CRD is not creating the access methods as expected. If there is an object in the CRD defined with configuration:
type: object
x-kubernetes-preserve-unknown-fields: true

It will generate a java class for that configuration, but the mapper will not fill the Map. Therefore the object will not contain any data.

Fabric8 Kubernetes Client version

6.2.0

Steps to reproduce

  1. Create a CRD having type object and x-kubernetes-preserve-unknown-fields: true
  2. generate the java code
  3. read a CR with additionalAttributes like
    - configuration:
    description: "Map does not contain this content"
    enabled: true
    name: "Erronious content"
  4. Use a mapper to read that yaml into you generated Java Object

All the addtionalAttributes are not present in the Map

Expected behavior

Every unknown field should be accessible with in that additionalAttributes map via the "key"; i.E. "description".


Proposal, instead of generating:

@com.fasterxml.jackson.annotation.JsonAnyGetter()
public java.util.Map<String, Object> getAdditionalProperties() {
    return additionalProperties;
}
@com.fasterxml.jackson.annotation.JsonAnySetter()
public void setAdditionalProperties(java.util.Map<String, Object> additionalProperties) {
    this.additionalProperties = additionalProperties;
}

we may need to generate

@com.fasterxml.jackson.annotation.JsonAnyGetter()
public java.util.Map<String, Object> any() {
    return additionalProperties;
}

@com.fasterxml.jackson.annotation.JsonAnySetter()
public void setAdditionalProperties(String name, Object value) {
    additionalProperties.put(name, value);
}

public Object getAdditionalProperties(String name) {
    return additionalProperties.get(name);
}

It definetly works for String objects as unknown entities. I don't know what happends with complex objects.

Runtime

Kubernetes (vanilla), other (please specify in additional context)

Kubernetes API Server version

1.25.3@latest

Environment

Windows

Fabric8 Kubernetes Client Logs

No response

Additional context

No response

@mteubner mteubner changed the title Additional Attributes are generated to be ignored, because of wrong setting of JsonAnyGetter annotation Additional Attributes are generated to be ignored, because of wrong setting of JsonAnySetter annotation Oct 31, 2022
@manusa
Copy link
Member

manusa commented Nov 4, 2022

cc @andreaTP

@andreaTP
Copy link
Member

andreaTP commented Nov 4, 2022

yup, looking into it, I'm 100% sure I tested this manually when implementing the support.
Now that we have proper integration tests we can fix it properly.
Apparently, some serialization/deserialization behaviors have been slightly changed.

@andreaTP andreaTP self-assigned this Nov 4, 2022
@andreaTP andreaTP added the bug label Nov 4, 2022
@manusa manusa added this to the 6.3.0 milestone Nov 14, 2022
manusa added a commit that referenced this issue Nov 14, 2022
Signed-off-by: Marc Nuri <marc@marcnuri.com>
@mteubner
Copy link
Author

Tested 6.3 looks good

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

Successfully merging a pull request may close this issue.

3 participants