I'am using camel to create a JAXB object, marshall it and write then the result in UTF-8 encoded XML file. Some of my xml content is fetched from a datasource which is using an ISO 8859-1 encoding:
hier is my camel route:
import org.apache.camel.converter.jaxb.JaxbDataFormat;
JaxbDataFormat jaxbDataFormat = new JaxbDataFormat(Claz.class.getPackage().getName());
from("endpoint")
.process(//createObjectBySettingTheDataFromSource)
.marshal(jaxbDataFormat)
.to(FILEENDPOINT?charset=utf-8&fileName=" +Filename);
The XML is generated successfully, but the data content fetched from the source still in the ISO encoding and not resolved with UTF8.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Name>M��e Faࠥnder</Name> //Mürthe Faßender
by changing the file encoding to ISO 8859-1 the content is resolved successfully.
I tried to convert the data before setting it in the JAXB object but still not resolved in UTF-8.
byte[] nameBytes = name.getBytes(StandardCharsets.ISO_8859_1);
return new String(nameBytes, StandardCharsets.UTF_8);
The problem is only accuring under Linux, does any one have an idea how to manipulate the ISO_8859_1 data and set it without issues in the xml ?
.removeProperty(Exchange.CHARSET_NAME)
to avoid the double charset change – Paizo