-
-
Notifications
You must be signed in to change notification settings - Fork 186
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
feat!: add jackson annotations additionalProperties #2103
feat!: add jackson annotations additionalProperties #2103
Conversation
✅ Deploy Preview for modelina canceled.
|
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.
additionalProperties
needs to be unwrapped, not simply serialized and deserialized 🙂
I dont think there is anything native in Jackson that supports that. Might be wrong though.
Hi, thanks for taking a look. What would unwrapped mean in this context? In my tests any unknown key/value pair was given its own entry in the map, and any object value would become a map of its own. |
serialized value if it's not possible we should just ignore the property and add it to the documentation |
In that case it does some wrapping/unwrapping. What happens is now (pseudocode): Json to deserialize: {
"defined_property": "defined property value",
"undefined_property": "undefined property value"
} Java class to unmarshal the JSON into: class JavaClassRepresentation {
// getters/setters/annotations and other methods omitted for brevity
private String definedProperty = "defined property value";
private Map<String, Object> additionalProperties = Map.of(
Entry.of("undefined_property", "undefined property value")
);
} Json serialized from the Java class: {
"defined_property": "defined property value",
"undefined_property": "undefined property value"
} The one edge case I am uncertain about is if an additional property is actually named |
@jonaslagoni The @JsonAnyGetter annotation ensures that the properties from the additionalProperties map are unwrapped on serialization. Do you think this change could be added? |
@memdal thats perfect yea: https://www.tutorialspoint.com/jackson_annotations/jackson_annotations_jsonanygetter.htm My bad for not realizing it before ✌️ confused it with regular getter method.. |
* Adds @JsonAnySetter and @JsonAnyGetter annotations to additionalProperties.
f05e1bd
to
3c2b25c
Compare
replace check for isAdditionalProperties with hasUnwrappedOptions when adding @JsonAnyGetter annotation.
Quality Gate passedIssues Measures |
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.
Nice 👍
@all-contributors please add @memdal for code, test |
I've put up a pull request to add @memdal! 🎉 |
🎉 This PR is included in version 4.0.0-next.62 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Description
Adds these annotations so that Jackson can marshall and unmarshall additional properties.
Checklist
npm run lint
).npm run test
).