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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.hubspot.jinjava.lib.filter;

import com.fasterxml.jackson.databind.node.POJONode;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.hubspot.jinjava.doc.annotations.JinjavaDoc;
import com.hubspot.jinjava.doc.annotations.JinjavaParam;
import com.hubspot.jinjava.doc.annotations.JinjavaSnippet;
import com.hubspot.jinjava.interpret.InvalidInputException;
import com.hubspot.jinjava.interpret.InvalidReason;
import com.hubspot.jinjava.interpret.JinjavaInterpreter;
import com.hubspot.jinjava.objects.date.PyishDate;
import java.util.Map;
Expand Down Expand Up @@ -48,7 +50,16 @@ public Object filter(Object var, JinjavaInterpreter interpreter, String... args)
) {
varStr = Objects.toString(var);
} else {
varStr = new POJONode(var).toPrettyString();
try {
varStr =
interpreter
.getConfig()
.getObjectMapper()
Comment on lines +55 to +57
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.

👍

.writerWithDefaultPrettyPrinter()
.writeValueAsString(var);
} catch (JsonProcessingException e) {
throw new InvalidInputException(interpreter, this, InvalidReason.JSON_WRITE);
}
}

return EscapeFilter.escapeHtmlEntities(
Expand Down