-
Notifications
You must be signed in to change notification settings - Fork 817
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
Java 14 records : how to deal with them? #735
Comments
There is no built-in support for records and there most likely won't be until the next Java LTS release. Serialization of records works very differently from "normal" classes:
You have a couple of options to deal with this:
|
Hi, I work on the JDK and I’d be happy to help with supporting record types. If you are planning on adding built-in support for records, I can share a custom serialiser I recently wrote. It’s an initial version that likely requires further review and discussion, but with about a year until the next Java LTS release, it could be a good start. To give some more background: As @payne911 mentioned, in JDK 14 the FieldSerializer can actually handle the record, provided it has a no-arg constructor. There is an illegal access warning, but the read operation completes. However, starting in JDK 15, core reflection will no longer be able to mutate the fields of a record object. In this case, the following exception is thrown when the FieldSerializer is initialised:
As you already mentioned, record serialization differs from regular serialization, and with JDK 15 this will manifest even more. For records, construction should then proceed through the canonical constructor. Again, I'd love to to help to make kryo work with records, so let me know if I can contribute in any way. |
@FrauBoes: Thank you so much for looking into this! It would be fantastic if you could share your custom serializer in a PR! That would be a great starting point to discuss the issue further. I'll see if I can adjust the build so we can compile against JDK14+. |
For reference: #766 |
How does KryoNet work with Java 14's records? Is there a recommended custom Serializer?
I'm getting:
Using lombok's
@NoArgsConstructor
does not allow the compiler to finish its work:And if I try with something like this:
I get:
The text was updated successfully, but these errors were encountered: