I also made a try : https://framagit.org/FBibonne/poc-java/-/tree/iso8859?ref_type=heads : this litle project tries to reproduce your context with the class ConfigRestClient which provides RestClients to retrieve Product entites (simplified version of your )
Then I made tests mocking a server which serves xml encoding with ISO-8859-1 : https://framagit.org/FBibonne/poc-java/-/blob/iso8859/src/test/java/poc/java/springrestclient/ConfigRestClientTest.java?ref_type=heads : each test configures a mock server to return xml, gets a ResClient from ConfigRestClient and calls retrieve with the RestClient as your method getStuff()
does.
The different tests try to explain the problem and suggest a fix :
faillingCallWithIso8859()
: reproduces the initial problem (checking the exception raised is about xml encodingtestOKWithUTF8()
checks it works if the server responses using UTF-8testOKWithCorrectHeaderXML()
tries a fix with the server side adding encoding in xml header : I think it is the ideal solutiontestOkWithClientFixingEncoding()
tries an other RestClient (provided by poc.java.springrestclient.ConfigRestClient#woEncodingFixingRestClient
) which intercept the response made by the spring ClientHttpRequest
and decode the body to re-encode it in UTF-8. this is a poor workaround because it requires to rewrite some spring code (class poc.java.springrestclient.ConfigRestClient.BodyReEncodedResponse which rewrites body like org.springframework.http.client.BufferingClientHttpResponseWrapper). But it works.If you introduced such a RestClient in your application, you would only use it for the problematic endpoint thanks to @Qualifier adn/or @Primary.
I don't think the problem resides in Spring RestClient : in fact, it seems impossible to set up externally the encoding used by Jaxb unmarshalling : see Override declared encoding during unmarshalling with JAXB : the suggested solution is to process byte decoding outside jaxb to control encoding. I neither found in Jaxb a way to do it : jakarta.xml.bind.helpers.AbstractUnmarshallerImpl#setProperty does not support any property set (raise exceptions)