-
Notifications
You must be signed in to change notification settings - Fork 175
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
Jackson property annotations are not working with data classes #56
Comments
can you please provide a small failing test case, thanks |
Sorry, was on a vacation. Here's the test
|
|
Thanks, looking at it now. |
The issue is obscured in older versions of Jackson, with 2.9 you now get the correct error:
Databind does not support |
A workaround for this, in case anyone arrives at this issue while searching for a solution to the problem: Change |
This would suggest that there might be something wrong (or missing) with constructor parameter usage, or discovery. In theory unwrapped should work in either place, but if constructor is not visible for some reason then this could follow. |
|
I couldn't get To summarize what works and what doesn't. This wont work
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot define Creator property "sku" as 1. hack to make it work
2. use lateinit I don't consider this a solution as it violates the proper way to instantiate an object. For example, if the constructor has all value objects (non primitives) then you need to put in a dummy property placeholder for it to work with a data class.
|
it does not work for deserializing neither. here is my code: data class Child(val name: String)
data class Parent(@field:JsonIgnore val child: Child) {
@get:JsonUnwrapped
private val _child: Child
get() = child
} error message:
it seems that we have to use normal class for class Parent {
@JsonUnwrapped
lateinit var child: Child
} |
i have only found the following "hack" to work properly and without too much dummy-fields-foobar:
coming from #91 (comment) |
You saved my day @hotzen ! Thanks |
I am using second constructor with @JsonCreator as workaround: data class Child(val name: String)
data class Parent(@field:JsonUnwrapped val child: Child) {
@JsonCreator
constructor(name: String): this(Child(name))
} |
While looking for a stop-gap solution for this in GitHub, I found this (usage) rather straightforward solution for |
@apatrida Not sure if I missed something in your suggestion, but I tried an attribute inside the body of the data class, but didn't work. Tried in both data classes and "regular classes". When I add an
If I try to deserialize this Json:
Then the |
@JsonUnwrapped annotations are not working for data classes failing with
not find creator property with name 'propertyname'
.Same structure with a regular class seems to work fine.
The text was updated successfully, but these errors were encountered: