-
Notifications
You must be signed in to change notification settings - Fork 170
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
Conversation
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.
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()); |
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.
What if ObjectMapper is not null? Shouldn't you register JavaTimeModule in that case?
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.
Yes, that's a good point. This will be addressed by the change Julia suggested.
interpreter | ||
.getConfig() | ||
.getObjectMapper() |
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.
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
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.
Good idea. I'll update.
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 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.
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.
Updated to remove module registration, but the remaining changes are still needed to support using the interpreter's config's ObjectMapper
.
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.
👍
public ZonedDateTime getDate() { | ||
return ZonedDateTime.of(2023, 12, 11, 0, 0, 0, 0, ZonedDateTime.now().getZone()); | ||
} |
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.
Is this method used?
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.
Yes, this tests that ZonedDateTime
(the problem type) is being serialized successfully.
interpreter | ||
.getConfig() | ||
.getObjectMapper() | ||
.registerModule(new JavaTimeModule()) |
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.
Does this mean we register the module every time the function is called? Is this an expensive operation?
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 raised the same question on an above thread.
I'm thinking it shouldn't be Jinjava's job to configure the If no TL;DR: I think the right place to add this module is where we're configuring our own |
interpreter | ||
.getConfig() | ||
.getObjectMapper() |
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.
👍
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> |
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.
Do you still need those POM update?
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.
Only for the test, but I'm going to move it into my upcoming cos-renderer
PR
Serializing
ZonedDateTime
is not supported by Jackson by default, so this PR registersJavaTimeModule
to add that support.