Avoid Instant and LocalDate GSON serialization errors (Java 17+) #48
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Mailersend uses the default GSON serializer for serializing some classes when using then
com.mailersend.sdk.emails.Email.serializeForSending
method. The default GSON serializer uses reflection to serialize such classes; this is not compatible with a change made in the JDK for Java 17 (see JEP 403 or https://github.com/google/gson/blob/main/Troubleshooting.md#-inaccessibleobjectexception-module--does-not-opens--to-unnamed-module) regarding reflection, causing acom.google.gson.JsonIOException
to be thrown when calling thecom.mailersend.sdk.emails.Email.serializeForSending
method.For the Mailersend client, this problem usually happens when you pass an Object that contains fields of type
java.time.LocalDate
orjava.time.Instant
to thecom.mailersend.sdk.emails.Email.addPersonalization
method and then send the email using thecom.mailersend.sdk.emails.Emails.send
method.GSON's suggested solution says:
As the second option would imply changing the
com.mailersend.sdk.emails.Email.addPersonalization
method or restricting the classes that can be serialized, I have implemented the first solution by adding TypeAdapters for thejava.time.LocalDate
andjava.time.Instant
classes.