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
[java-generator] Fix additionalProperties ser/deser #4561
Conversation
cc @mteubner |
@@ -82,4 +82,9 @@ public class Auth implements io.fabric8.kubernetes.api.model.KubernetesResource | |||
public void setAdditionalProperties(java.util.Map<String, Object> additionalProperties) { | |||
this.additionalProperties = additionalProperties; | |||
} | |||
|
|||
@com.fasterxml.jackson.annotation.JsonAnySetter() | |||
public void setAdditionalProperties(String key, Object value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be setAdditionalProperty singular?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surprisingly not, the integration test fails if I make it singular.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So probably some jackson magic :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, at least now is properly tested 🙂
java-generator/core/src/main/java/io/fabric8/java/generator/nodes/JObject.java
Outdated
Show resolved
Hide resolved
@@ -280,6 +282,13 @@ public GeneratorResult generateJava() { | |||
|
|||
objField.createGetter().addAnnotation("com.fasterxml.jackson.annotation.JsonAnyGetter"); | |||
objField.createSetter().addAnnotation("com.fasterxml.jackson.annotation.JsonAnySetter"); | |||
|
|||
MethodDeclaration additionalSetter = clz.addMethod("setAdditionalProperties", Modifier.Keyword.PUBLIC); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MethodDeclaration additionalSetter = clz.addMethod("setAdditionalProperties", Modifier.Keyword.PUBLIC); | |
MethodDeclaration additionalSetter = clz.addMethod("setAdditionalProperty", Modifier.Keyword.PUBLIC); |
Sorry, I may not be being clear. I would expect both the test and this logic to say setAdditionalProperty singular. That lines up with the model generation logic in the main project - Pod.setAdditionalProperty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, that's what I did, changing both breaks the functionality I'm fixing here as demonstrated by the additional test included in this PR.
If you are still in doubt I propose to have a quick sync on it to clarify somewhere next week ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, it would probably be best to compare to what's already in use. The core model classes are generated with:
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}
due to a limitation in the jsonschema2pojo,
@JsonIgnore
void setAdditionalProperties(Map<String, Object> properties)
being generated by the class annotations:
@Setter
@Accessors(prefix = {
"_",
""
})
As far as I know that handles all of the issues we have seen with serdes and builder logic.
Could you try aligning to that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shawkins sorry for the long forth and back, the integration test failure was due to a different reason ... fixed now 👍
Kudos, SonarCloud Quality Gate passed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Signed-off-by: Marc Nuri <marc@marcnuri.com>
@andreaTP Do I do something wrong on that? When I check out the master branch, und try to build this test, I still get package io.dapr.v1alpha1.componentspec; @com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
}@mteubner you should execute mvn install, if you want to use the new code, not verify :( @andreaTP workgs fine for me, thx a lot |
Description
Fix #4543
Type of change
test, version modification, documentation, etc.)
Checklist