-
-
Notifications
You must be signed in to change notification settings - Fork 177
Deserialization issue, @JsonCreator ignored #932
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
Comments
Which constructor are you expecting to call? |
@cowtowncoder This may be another Kotlin module issue post-property-introspection-rewrite in databind. Solution idea... short termI wonder if instead we can...
Opinion on long-termRegardless, we want to slim down |
@JooHyukKim Since I will see if it can be reproduced in |
I have submitted the issue to |
It may be superfluous, but I personally felt that it would be better to change the data class User private constructor(
val age: Int,
val firstName: String,
val lastName: String,
) {
private constructor(age: Int, fullName: List<String>) : this(age, fullName[0], fullName[1])
constructor(age: Int, fullName: String) : this(age, fullName.split(" "))
} Also, given the generation rules regarding data class FullName(
val firstName: String,
val lastName: String,
) {
companion object {
fun fromRawFullName(fullName: String) = fullName.split(" ").let {
if (it.length != 2) throw TODO()
FullName(it[0], it[1])
}
}
}
data class User private constructor(
val age: Int,
val firstName: String,
val lastName: String,
) {
constructor(age: Int, fullName: FullName) : this(age, fullName.firstName, fullName.lastName)
} |
Hello, indeed the dto is not well structured but let's say I can't modify it due to "legacy" reasons. 🙃 Thanks for digging Also, even by adding @JsonIgnore or @Creator(mode=DISABLED) to the default constructor it is not ignored. |
FWTW, Why former is not ignored is probably due to changes in processing -- some Creators are kept in processing list for a bit before removed so maybe accidentally passed to method that selects the preferred Creator. |
Search before asking
Describe the bug
Hello,
While updating to spring boot 3.4.x I faced an issue related to the upgrade of jackson dependencies from 2.17.3 to 2.18.2
Deserialization is not working anymore for a class with 2 constructor, one with @JsonCreator annotation.
It fails with this exception:
It seems it take the wrong constructor, I also try with
@JsonIgnore
and@JsonCreator(mode=DISABLED)
on the first constructor but it didn't help.Any idea on how to solve this issue?
To Reproduce
Project with failing test can be found on this repo https://github.com/fabienfleureau/jackson-deserialization-issue/
I have defined this class:
and the json to deserialize looks like this:
Expected behavior
I expected to have a user deserialized having age set to 25, firstName set to Jane and lastName set to Doe
Versions
Kotlin: 2.1
Jackson-module-kotlin: 2.18.3
Jackson-databind: 2.18.3
Additional context
also created an issue in databind FasterXML/jackson-databind#5040 but someone suggested to ask here
The text was updated successfully, but these errors were encountered: