Skip to content
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 serialization #1223

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

eranl
Copy link
Contributor

@eranl eranl commented Mar 4, 2023

With this change, java records will be serialized using their automatic constructors and accessors. Since records are not supported in JDK8, reflection is used for inspecting record metadata.

I created a new google-cloud-firestore-jdk17 module, for two purposes:

  1. Test classes for records, which require jdk17
  2. DocumentId, PropertyName, and ServerTimestamp annotations with @target(ElementType.RECORD_COMPONENT), which also require jdk17

Fixes #1152 ☕️

Some comments and questions:

  1. Since only automatic constructors are supported, exclusion of fields is not supported
  2. Custom getters are not supported
  3. The existing ThrowOnExtraProperties & IgnoreExtraProperties annotations are supported
  4. I put the new logic outside of CustomClassMapper for readability, and extracted some of the existing logic out of it, for reuse. Everything is package-private. It can all be easily moved (back) into CustomClassMapper.
  5. I based the tests on existing tests for POJOs, and adapted them to records
  6. Two of the test classes use the com.google.cloud.firestore java package, in order to have access to FirestoreImpl, which is needed for mocking
  7. Should the new google-cloud-firestore-jdk17 module be moved to a separate project?
  8. The code currently accepts any annotations with the simple names DocumentId, PropertyName, and ServerTimestamp, for flexibility. That can be changed to require the FQNs.

@eranl eranl requested review from a team as code owners March 4, 2023 00:31
@product-auto-label product-auto-label bot added size: xl Pull request size is extra large. api: firestore Issues related to the googleapis/java-firestore API. labels Mar 4, 2023
@eranl
Copy link
Contributor Author

eranl commented Mar 30, 2023

CI failures seem to all be in the new JDK17 module I added, which adds weight to my question # 7 above

@eranl
Copy link
Contributor Author

eranl commented Jun 12, 2023

Hi @tom-andersen, any update on this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: firestore Issues related to the googleapis/java-firestore API. size: xl Pull request size is extra large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for serializing java record types
2 participants