Spring Boot currently autoconfigures the Mustache.Compiler like:
@Bean
@ConditionalOnMissingBean
public Mustache.Compiler mustacheCompiler(TemplateLoader mustacheTemplateLoader) {
return Mustache.compiler().withLoader(mustacheTemplateLoader);
}
To register a custom formatter one has to provide the Mustache.Compiler bean him/herself like:
@Bean
public Mustache.Compiler mustacheCompiler(Mustache.TemplateLoader mustacheTemplateLoader) {
return Mustache.compiler()
.withLoader(mustacheTemplateLoader)
.withFormatter(new Mustache.Formatter() {
public String format (Object value) {
if (value instanceof Date) return _fmt.format((Date)value);
else return String.valueOf(value);
}
protected DateFormat _fmt = new SimpleDateFormat("yyyy/MM/dd");
});
}
It would be nice if Spring Boot would recognize a Mustache.Formatter bean and auto configure them.
See also: https://github.com/samskivert/jmustache#user-defined-object-formatting
Comment From: wilkinsona
Thanks for the suggestion. This duplicates part of https://github.com/spring-projects/spring-boot/issues/15566.