if (parentTypeConverter != null) {
// lets convert the object to a JAXB source and try convert that to
// the required source
JAXBContext context = createContext(value.getClass());
// must create a new instance of marshaller as its not thread safe
Marshaller marshaller = context.createMarshaller();
Writer buffer = new StringWriter();
boolean prettyPrint = isPrettyPrint();
// check the camel context property to decide the value of PrettyPrint
if (exchange != null) {
String property = exchange.getContext().getProperty(PRETTY_PRINT);
if (property != null) {
if (property.equalsIgnoreCase("false")) {
prettyPrint = false;
} else {
prettyPrint = true;
}
}
}
if (prettyPrint) {
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
}
if (exchange != null && exchange.getProperty(Exchange.CHARSET_NAME, String.class) != null) {
marshaller.setProperty(Marshaller.JAXB_ENCODING, exchange.getProperty(Exchange.CHARSET_NAME, String.class));
}
if (needFiltering(exchange)) {
XMLStreamWriter writer = parentTypeConverter.convertTo(XMLStreamWriter.class, buffer);
FilteringXmlStreamWriter filteringWriter = new FilteringXmlStreamWriter(writer);
marshaller.marshal(value, filteringWriter);
} else {
marshaller.marshal(value, buffer);
}
// we need to pass the exchange
answer = parentTypeConverter.convertTo(type, exchange, buffer.toString());
}