I am using rest template to call API, when I hit the API using rest template it returns some garbled characters like Chinese.
ResponseEntity<String> response = restTemplate.exchange(url, method, entity, String.class);
When I hit the same API using Unirest or Postman, it returns response in JSON. I searched and tried to figure it out but there is a constraint that I can't do changes in the code either I do change in application.yml or pom.xml but can not change at the code level.
<200,笀∀爀攀焀甀攀猀琀䐀愀琀攀吀椀洀攀∀㨀∀㈀ ㈀㐀ⴀ 㜀ⴀ㈀㌀吀 㨀㈀㨀㠀⸀㜀 㜀㘀㐀㐀⬀ 㔀㨀 ∀Ⰰ∀氀漀最䤀搀∀㨀∀㈀㜀 㜀昀戀ⴀ 攀㤀戀ⴀ㐀㐀戀搀ⴀ㤀搀 㠀ⴀ㔀㔀㌀㔀搀㜀搀 戀昀∀Ⰰ∀挀漀搀攀∀㨀∀䴀匀䜀ⴀ ∀Ⰰ∀猀攀瘀攀爀椀琀礀∀㨀∀匀甀挀挀攀猀猀∀Ⰰ∀挀漀渀琀攀渀琀∀㨀∀攀礀䨀栀戀䜀挀椀伀椀䨀䤀唀稀䤀一椀䤀猀䤀渀刀㔀挀䌀䤀㘀䤀欀瀀堀嘀䌀䨀㤀⸀攀礀䨀戀洀氀砀搀圀嘀昀戀洀䘀琀娀匀䤀㘀䤀洀䤀㐀娀䐀䔀㈀䴀圀䔀礀䰀圀夀㈀夀樀挀琀一䐀䴀砀一礀栀夀樀䔀 䰀吀欀㌀䴀䐀最稀伀吀䴀㐀娀圀䔀㐀䴀椀䤀猀䤀洀㔀椀娀椀䤀㘀䴀吀挀礀䴀吀挀砀䴀樀䄀㌀伀䌀眀椀娀堀栀眀䤀樀漀砀一稀䤀砀一稀䔀一樀挀㐀䰀䌀䨀瀀夀堀儀椀伀樀䔀㌀䴀樀䔀㌀䴀吀䤀眀一稀栀㤀⸀挀䤀䄀攀䈀砀ⴀ瘀爀吀娀匀㠀㤀㠀甀㈀䄀㔀娀䰀㔀䴀倀䔀愀 爀欀伀儀瘀堀漀ⴀ樀ⴀ洀䤀礀唀 ∀Ⰰ∀攀爀爀漀爀∀㨀渀甀氀氀紀,{Content-Length=[780], Content-Type=[application/json; charset=utf-16], Server=[Microsoft-IIS/10.0], Date=[Tue, 23 Jul 2024 05:21:18 GMT]}>
This is the response I get.
And I want response in the below format.
<200,{requestDateTime=2024-07-23T10:23:45.9429614+05:00, logId=e7dc9988-2a2a780b54c6, code=200, severity=Success, content=eyJNiIsInR5cCI6IkpXVCJhbGciOiJIUzI19.eyJ1bSI6ImI4ZDE2MWEyMTIyMjV9LWY2mlxdWVfbmFtZYjctNDMcyMTcxMjIyNSwiZXhwIjoxNzIxNzE1ODI1LCJpYXQiOjE3MjxNy1hYjE0LTk3MDgzOTM4ZWE4MiIsIm5iZiI6MTE3.yGUCZ83YVYw7XOuXrIl79ONCYVuxKS5MbtB_XxG9wyE, error=null},{Content-Length=[780], Content-Type=[application/json; charset=utf-16], Server=[Microsoft-IIS/10.0], Date=[Tue, 23 Jul 2024 05:23:45 GMT]}>
I receive the above expected response when I change the return to 'Object.class' but as I said earlier I can't make that change. I have also made the following changes in my application.yml file:
spring.mandatoryFileEncoding=UTF-8spring.http.encoding.charset=UTF-8spring.http.encoding.enabled=truespring.http.encoding.force=true
And following changes in pom.xml:
<properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding></properties>
But nothing works for me. Kindly suggest me is there any possible solution to get the response in JSON format without making changes in the code.
TIA.