From 83d56c0bb1e3d18f7f54aee401c09fc6c79bfa4a Mon Sep 17 00:00:00 2001 From: xhaggi Date: Fri, 31 May 2024 11:23:01 +0200 Subject: [PATCH] [fix] Invalid characters (CR/LF) in response header caused by customized Jackson ObjectMapper Due to the fact that a user can customize the Jackson ObjectMapper bean (e.g. spring.jackson.serialization.indent-output=true) in Spring Boot, this leads to unwanted errors when it comes to serializing. Therefore, we no longer rely on this ObjectMapper. --- .../htmx/spring/boot/mvc/HtmxMvcAutoConfiguration.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htmx-spring-boot/src/main/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxMvcAutoConfiguration.java b/htmx-spring-boot/src/main/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxMvcAutoConfiguration.java index 3524d65..c59806e 100644 --- a/htmx-spring-boot/src/main/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxMvcAutoConfiguration.java +++ b/htmx-spring-boot/src/main/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxMvcAutoConfiguration.java @@ -1,6 +1,7 @@ package io.github.wimdeblauwe.htmx.spring.boot.mvc; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.json.JsonMapper; import org.springframework.beans.factory.ObjectFactory; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.autoconfigure.AutoConfiguration; @@ -26,14 +27,13 @@ public class HtmxMvcAutoConfiguration implements WebMvcRegistrations, WebMvcConf private final ObjectMapper objectMapper; HtmxMvcAutoConfiguration(@Qualifier("viewResolver") ObjectFactory resolver, - ObjectFactory locales, - ObjectMapper objectMapper) { + ObjectFactory locales) { Assert.notNull(resolver, "ViewResolver must not be null!"); Assert.notNull(locales, "LocaleResolver must not be null!"); this.resolver = resolver; this.locales = locales; - this.objectMapper = objectMapper; + this.objectMapper = JsonMapper.builder().build(); } @Override