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

Fix serialization of ZonedDateTime #1135

Merged
merged 6 commits into from
Dec 12, 2023
Merged

Conversation

maple-buice
Copy link
Contributor

Serializing ZonedDateTime is not supported by Jackson by default, so this PR registers JavaTimeModule to add that support.

@maple-buice maple-buice requested a review from tkindy December 11, 2023 16:55
Copy link

@niketpatel2525 niketpatel2525 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -157,7 +158,8 @@ private JinjavaConfig(Builder builder) {

private ObjectMapper setupObjectMapper(@Nullable ObjectMapper objectMapper) {
if (objectMapper == null) {
objectMapper = new ObjectMapper();
objectMapper = new ObjectMapper().registerModule(new JavaTimeModule());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if ObjectMapper is not null? Shouldn't you register JavaTimeModule in that case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's a good point. This will be addressed by the change Julia suggested.

Comment on lines +55 to +57
interpreter
.getConfig()
.getObjectMapper()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on registering the module here so we scope the change to the object mapper to the pretty print filter? I think my concern here is if changing the mapper on the config level will inadvertently change something else

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I'll update.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think registering here is the right move. This will register the module on every call to the PrettyPrintFilter.

I need to look through the PR to figure out where the right place to do it would be.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to remove module registration, but the remaining changes are still needed to support using the interpreter's config's ObjectMapper.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines 99 to 101
public ZonedDateTime getDate() {
return ZonedDateTime.of(2023, 12, 11, 0, 0, 0, 0, ZonedDateTime.now().getZone());
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this method used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this tests that ZonedDateTime (the problem type) is being serialized successfully.

interpreter
.getConfig()
.getObjectMapper()
.registerModule(new JavaTimeModule())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean we register the module every time the function is called? Is this an expensive operation?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I raised the same question on an above thread.

@tkindy
Copy link
Contributor

tkindy commented Dec 11, 2023

I'm thinking it shouldn't be Jinjava's job to configure the ObjectMapper passed in by the caller. If the caller wants to use the JavaTimeModule, they should configure that themselves.

If no ObjectMapper is passed in, I still don't think the one Jinjava builds should add anything extra unless Jinjava specifically needs them for its purposes. If it's just to properly serialize user-provided input, that should be on the caller to configure properly.

TL;DR: I think the right place to add this module is where we're configuring our own Jinjava instance internally, not in the library itself.

Comment on lines +55 to +57
interpreter
.getConfig()
.getObjectMapper()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

pom.xml Outdated
@@ -83,6 +83,11 @@
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.14.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you still need those POM update?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only for the test, but I'm going to move it into my upcoming cos-renderer PR

@maple-buice maple-buice merged commit 61acbfb into master Dec 12, 2023
4 checks passed
@maple-buice maple-buice deleted the 958-fix-ZonedDateTime branch December 12, 2023 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants