Problem with UTF-8
- by Pablo Fernandez
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);