-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Primitive to record mapping fails to find constructor #3381
Comments
Records are not just treated as normal classes by jackson. e.g. the getter names are different, and property names for the constructor are known. If you want the same behavior as a normal class, you can annotate the constructor explicitly: record ProviderRecord(Long refId) {
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
ProviderRecord {}
} |
Hi @yawkat Thank you very much for the very fast response. But just to understand, for records, there is no way of the deserialization flow to work without the @JsonCreator annotation? I'm just trying to have a notion if what I'm talking is a bug indeed or, if is in fact the intended way of working, if I should open a new feature request. Best regards |
I can't answer authoritatively whether this should be a feature or anything – I don't work on jackson-databind, I just try to help with the issue reports a bit.
|
Yes, the default assumption is --based on typical As to Other than that, yes, I hope this helps. |
Starting from 2.15.0 (thanks to #3724 + #3654), you can also use
...since if you want to deserialize a scalar value into a Record, naturally you should also want to serialize the Record into scalar value... |
BUT if you're only using that Record for deserialization & you really prefer not having to annotate, you can also do this starting from 2.15.0 (thanks to #3724):
|
Describe the bug
Jackson not able to use same deserialization strategy in records that uses in classes.
Version information
2.13.1
To Reproduce
The second test will fail with the message:
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of
com.carepay.visitservice.ProviderRecord(although at least one Creator exists): no int/Int-argument constructor/factory method to deserialize from Number value (1)
Expected behavior
It was to expect that the same behavior to deserialize using only the constructor would be possible in the records as it happens on the class.
Additional context
Compact or Canonical record constructors, as well as the record visibility, makes no difference in the outcome.
The text was updated successfully, but these errors were encountered: