-
Notifications
You must be signed in to change notification settings - Fork 31
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
Add support for Java Record deserialization #148
Add support for Java Record deserialization #148
Conversation
private static Method getTypeMethod; | ||
|
||
static { | ||
Method isRecordMethod; |
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.
I think we can avoid this one... see note below.
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.
jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/RecordsHelpers.java
Outdated
Show resolved
Hide resolved
jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/BeanReader.java
Outdated
Show resolved
Hide resolved
@TomaszGaweda GREAT contribution, thank you! I added some notes on changes needed; nothing major, just some streamlining. One thing I'd need, aside from doing review, is CLA, from: https://github.com/FasterXML/jackson/blob/master/contributor-agreement.pdf (unless you have done one before; apologies if I missed it) This is only needed once before merging the first contribution. Usually it's easiest to print, fill & sign, scan/photo, email to Once again, big thank you for contribution this & let's get it merged in for 2.18(.0)! |
BTW. Should I somehow notice that RecordHelpers is based on Hazelcast's JavaRecordSerializer? I am Hazelcast's contractor, but this work is done privately. Hz code is under Apache 2 as well |
CLA signed and sent, CR comments addressed :) |
I think |
Getting required method references is indeed generic enough - core logic had to be implemented here. I've rerequested review @cowtowncoder, thanks for your support! |
jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/BeanConstructors.java
Outdated
Show resolved
Hide resolved
jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/BeanReader.java
Outdated
Show resolved
Hide resolved
jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/RecordsHelpers.java
Outdated
Show resolved
Hide resolved
Thank you @TomaszGaweda -- made some final tweaks (wrt since tags, add release notes), ready to go! In future there may need to try to support annotation override (via jackson annotations extension), but for basic usage this should work nicely.. |
Hmmh. Unfortunately, didn't realize this but I don't think our Record test is running at all... Will need to figure why, how to fix -- it appears to try to use JUnit 5, although all (other) tests are JUnit4 |
Assert.assertEquals(expectedString, json); | ||
|
||
Cow object = jsonParser.beanFrom(Cow.class, json); |
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.
Here is some feedback on other variants of input data.
a) different order of fields in JSON than in Java record
input: {"object":{"Foo":"Bar"}, "message":"MOO"}
result: Failed to create an instance of jr.Java17RecordTest$Cow due to (java.lang.IllegalArgumentException): argument type mismatch
This should get fixed.
b) missing field in JSON
input: {"message":"MOO"}
result: Failed to create an instance of jr.Java17RecordTest$Cow due to (java.lang.IllegalArgumentException): wrong number of arguments
I am wondering how deserialization to records should handle missing data as the all-args record constructor requires all fields and if there should also be support for Optional
like provided by jackson-modules-java8
.
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.
@darxriggs Could you file a separate issue for the problem with ordering? We definitely need more testing here. It can include part about missing values as well (no need for 2 issues).
As to missing values: should pass null
, although this will be problematic for many cases like primitives.
These can be addressed incrementally; Optional
isn't yet supported for anything else yet so it can be deferred.
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.
Thanks @darxriggs, I've included your feedback in a follow-up: #163
jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/BeanReader.java
Show resolved
Hide resolved
Ok, no, this simply does not work as-is. I will have to revert this for now. |
Added support for record deserialization.
It is based on new Java's reflection methods, added with records. If record classes are not supported, code should follow normal path.
Difference from standard deserialization: properties are not set one-by-one, but caches in
values
array and then passed to all-arg constructor (always present in records)