I'm consuming this XML:
<SomePerson>
<Number>1</Number>
<Name>Талантбек</Name>
<Surname>Ормонов</Surname>
<Patronomic>Шарипжанович</Patronomic>
<DataBirth>13.05.1987</DataBirth>
<PlaceBirth>Ошская область, Фрунзенский район</PlaceBirth>
<BasicInclusion>Приговор Аламудунского районного суда от 25.09.2017 г.</BasicInclusion>
<CategoryPerson>экстремист</CategoryPerson>
<DateInclusion>2018-05-21</DateInclusion>
</SomePerson>
as follows:
final String response = new RestTemplateBuilder()
.build()
.getForObject("someURL", String.class);
// Do something with string response
final JAXBContext jaxbContext = JAXBContext.newInstance(MyClass.class);
final Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
final JAXBElement<MyClass> sanctionList = jaxbUnmarshaller.unmarshal(new StreamSource(new ByteArrayInputStream(response.getBytes(StandardCharsets.UTF_8))), MyClass.class);
But all I see in the database:
and in my JSON api/frontend is:
Гулзина Качкыновна Орозбекова
Шохобидин Шарабидинович Ðурматов
Талантбек Шарипжанович Ормонов
Жибек Ðркинбековна Омуркулова
I've tried using ru_RU.UTF-8
encoding for my Postgres database, and got the same result with UTF-8
. What is causing this? Is this database related or the client/Java related or even Spring's RestTemplate
related?
CodePudding user response:
It was caused by the bad encoding in HTTP transport, credit to a_horse_with_no_name Fixed by:
final String response = new RestTemplateBuilder()
.messageConverters(new StringHttpMessageConverter(StandardCharsets.UTF_8))
.build()
.getForObject("someURL", String.class);