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.

3
  • why are you mixing 2 char sets? Commented Aug 29, 2019 at 17:16
  • I'm getting string in utf-8 format and trying to decode that to winsows-1251. Commented Aug 30, 2019 at 6: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... Commented Aug 30, 2019 at 7:45

1 Answer 1

0

You can try with this one

String decoded = new String(xmlstring.getBytes("ISO-8859-1")); 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.