Spring boot with Jackson2 assumes any JSON request will be Unicode and fails to tolerate non ascii characters if the encoding is not Unicode.
I saw that might be different by using GSON instead of Jackson2 but I want to try to stick to Jackson2.
Jackson2 supports any Java supported encoding and SpringBoot supports handling any of those encodings too but when working together they assume Unicode.
SpringBoot will assume all requests are UTF-8 unless you dissactivate that behaviour:
server.servlet.encoding.force-request=false
But then the method org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.read(Type, Class<?>, HttpInputMessage) doesn't have access to the request but it can access the headers in HttpInputMessage but it doesn't on SpringBoot 1.5.10.
It passes the InputStream to Jackson2 without encoding specification and it assumes it's Unicode.
The solution would be to create a InputStreamReader with the encoding you can find in the headers.
It seem's that's the actual behaviour in the current version of SpringBoot but I wonder if I can override the old one in SpringBoot 1.5.10 somehow.
I can extend the class MappingJackson2HttpMessageConverter but I don't know how to make SpringBoot to use the new converter instead of the default one for Jackson2.
I could mess with the classpath to override the whole AbstractJackson2HttpMessageConverter with a custom version but I wouldn't like that as it might break things if I make a fat-jar or a war and maybe other ways too.
I found a way to customize
MappingJackson2HttpMessageConverterby registering a new bean so I created this configuration class to register an instance of a subclass with the charset behaviour fixed, creating and using aReaderwhen the charset is not Unicode.