1

I'm getting xml file which I need to handle in my SpringBoot Rest controller. But I have problem with parsing cyrillic chars. In my controller these symbols look like this: d�鲲㮮弯.

I was trying to decode using

 new String(xmlstring.getBytes("UTF-8"), "Windows-1251")

Also I was trying add to my controller:

 consumes = "application/json; charset=UTF-8"

Top of my controller looks like this:

 @PostMapping(value = "/endpoint", produces = "text/xml; charset=windows-1251", consumes = "application/json; charset=UTF-8")
 @ApiOperation("...")
 public ResponseEntity<String> get(@RequestBody String xml) 

I need to parse that to standart cyrillic shape. Thank you.

RomanK
  • 47
  • 5
  • why are you mixing 2 char sets? – Kalpesh Soni Aug 29 '19 at 17:16
  • I'm getting string in utf-8 format and trying to decode that to winsows-1251. – RomanK Aug 30 '19 at 06:28
  • 1
    Strings by themselves (conceptually) don't have an encoding. The encoding determines how a string is represented when converted to and from bytes. Your first line of code is not correct: it encodes the string using UTF-8 and then decodes it as if it is Windows-1251. That's wrong, the bytes don't represent a Windows-1251-encoded string, because you've just encoded it as UTF-8... – Jesper Aug 30 '19 at 07:45

1 Answers1

0

You can try with this one

String decoded = new String(xmlstring.getBytes("ISO-8859-1")); 
Dulaj Kulathunga
  • 1,248
  • 2
  • 9
  • 19