spring-boot icon indicating copy to clipboard operation
spring-boot copied to clipboard

Use Charset instead of String for Mustache template encoding

Open ddongjunn opened this issue 1 month ago • 5 comments

The MustacheResourceTemplateLoader previously defined the template encoding as a String, defaulting to "UTF-8". This change replaces the field with a Charset and initializes it with StandardCharsets.UTF_8.

Using Charset improves type safety and aligns with modern Spring Boot standards, while avoiding implicit charset lookup issues.

ddongjunn avatar Nov 29 '25 16:11 ddongjunn

This would be a breaking change since MustacheResourceTemplateLoader.setCharset(String) is public API. I think we could add an overloaded method at some point and possibly also deprecate org.springframework.boot.mustache.autoconfigure.MustacheProperties.getCharsetName().

philwebb avatar Nov 29 '25 17:11 philwebb

@philwebb what needs amendements? Perhaps we can share that with @ddongjunn so they rework their original proposal.

snicoll avatar Nov 30 '25 14:11 snicoll

@philwebb Thanks for the feedback!

I’ve updated the PR to add the setCharset(Charset) overload while keeping the existing String-based method for backward compatibility (now deprecated). I also deprecated MustacheProperties.getCharsetName() as suggested.

This keeps the change backward compatible while providing a more type-safe API.

Let me know if you’d like any further adjustments.

ddongjunn avatar Dec 01 '25 05:12 ddongjunn

This PR is ready to be merged once main switches to 4.1.0-SNAPSHOT.

@ddongjunn thanks for the PR. To be consistent more work was required, see https://github.com/snicoll/spring-boot/commit/65cd92f58cb5b82c6de3b6c1dbd1507143b81c66. When something is deprecated, our code base should not call it anymore. Then searching for the same pattern in the rest of the module for consistency revealed a number of other usages not covered initially. It's all done now and will be merged once we can.

snicoll avatar Dec 01 '25 09:12 snicoll

@snicoll Thanks for reviewing and refining the PR. I appreciate the consistency updates and the clear explanation. Glad to hear it will be merged once 4.1.0-SNAPSHOT opens.

ddongjunn avatar Dec 01 '25 10:12 ddongjunn