use of org.apache.camel.dataformat.bindy.BindyAbstractFactory in project camel by apache.
the class BindyKeyValuePairDataFormat method marshal.
@SuppressWarnings("unchecked")
public void marshal(Exchange exchange, Object body, OutputStream outputStream) throws Exception {
final BindyAbstractFactory factory = getFactory();
final byte[] crlf = ConverterUtils.getByteReturn(factory.getCarriageReturn());
final TypeConverter converter = exchange.getContext().getTypeConverter();
// the body may not be a prepared list of map that bindy expects so help
// a bit here and create one if needed
final Iterator<Object> it = ObjectHelper.createIterator(body);
while (it.hasNext()) {
Object model = it.next();
Map<String, Object> row;
if (model instanceof Map) {
row = (Map<String, Object>) model;
} else {
row = Collections.singletonMap(model.getClass().getName(), model);
}
String result = factory.unbind(row);
outputStream.write(converter.convertTo(byte[].class, exchange, result));
outputStream.write(crlf);
}
}
Aggregations