Skip to content

How to handle java.time.Instance, LocalDateTime, etc., as render-able output? #447

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

Closed
bkuntzelman opened this issue Apr 4, 2025 · 3 comments
Labels
question Further information is requested

Comments

@bkuntzelman
Copy link

bkuntzelman commented Apr 4, 2025

For example, any type/class I have that references LocalDateTime gives an error message:

"no suitable method found for writeUserContent(java.time.LocalDateTime)"

How do we add our own "custom renderers" that don't already have support?

Am I completely missing how to do this in the documentation?

I'm running under Spring Boot 3.3.10 and JTE 3.1.16.

Thanks!

@edward3h
Copy link
Collaborator

edward3h commented Apr 4, 2025

Somewhere you're going to want to use a DateTimeFormatter to turn your value into a String.

The localization page in the documentation has some ideas that could work for this too.

@edward3h edward3h added the question Further information is requested label Apr 4, 2025
@boonyasukd
Copy link

You can read more info here.

Since toString() isn't automatically called like other templating frameworks due to security concerns, you will have to output your data down to primitive types yourself.

For my case, I'm using Kotlin, so I just ended up implementing extension methods on data types I'm interested in. In Java, you probably have to create and import static utility methods instead.

@bkuntzelman
Copy link
Author

Okay, thanks. Once I dug into it a bit deeper, I expected that's what was necessary. Thanks for confirming I wasn't missing some documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants