I currently have to deal with a REST API using text/xml;charset=ISO-8859-1
as MediaType. So just using MappingJackson2XmlHttpMessageConverter
seemed obvious to me. Unfortunately I found myself with
RestClientException: No HttpMessageConverter for ... and content type "text/xml;charset=ISO-8859-1"
As it turns out, inheriting from AbstractJackson2HttpMessageConverter
checks for hard-coded UTF encodings when calling MappingJackson2XmlHttpMessageConverter.canWrite()
https://github.com/spring-projects/spring-framework/blob/65553f55d7f18c0a79cc593a2dc3c9dd9413e5d2/spring-web/src/main/java/org/springframework/http/converter/json/AbstractJackson2HttpMessageConverter.java#L84-L92 https://github.com/spring-projects/spring-framework/blob/65553f55d7f18c0a79cc593a2dc3c9dd9413e5d2/spring-web/src/main/java/org/springframework/http/converter/json/AbstractJackson2HttpMessageConverter.java#L273-L283
which is totally reasonable for JSON but not for XML. Overriding this method is not a problem at all but I wanted you to be notified at least.
Comment From: sdeleuze
After having a deeper look, I am going to decline this issue due to assumptions hardcoded in Jackson JsonEncoding
, what was discussed in #25076 and given the fact https://github.com/FasterXML/jackson-dataformat-xml/issues/315 is opened for years. There are workarounds possible but we would need to change totally the Jackson converter and codec hierarchy, so I prefer to wait for first-class support for that in Jackson.
For now, please use Jaxb2RootElementHttpMessageConverter
if you have such need.
Comment From: mrpiggi
I should have looked more carefully for old issues. Sorry about that. Thanks for pointing to
Jaxb2RootElementHttpMessageConverter
that's exactly the way I went.
Sorry for the noise...