Problem with UTF-8
Posted
by Pablo Fernandez
on Stack Overflow
See other posts from Stack Overflow
or by Pablo Fernandez
Published on 2010-05-20T00:53:14Z
Indexed on
2010/05/20
1:00 UTC
Read the original article
Hit count: 612
I'm using castor as an OXM mapper, and I'm having a problem with UTF-8 encoding.
The code here shows the issue:
//Marshaller configuration
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStreamWriter os = new OutputStreamWriter(baos, UTF_8);
Marshaller marshaller = new Marshaller(os);
marshaller.setSuppressXSIType(true);
//Mappings configuration
Mapping map = new Mapping();
map.loadMapping(MarshallingService.class.getResource(MAPPINGS_PATH));
marshaller.setMapping(map);
//Example
//BEFORE MARSHALLING: This prints correctly the UTF-8 Chars
object.getName() ;
marshaller.marshal(object);
//AFTER MARSHALLING: This returns the characters like \435\235\654\345
return baos.toString(UTF_8);
© Stack Overflow or respective owner