try {
OutputStream outStream = csb.getOutputStream();
XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outStream, DEFAULT_CHARSET);
writer.writeStartDocument(DEFAULT_CHARSET, XML_VERSION);
XmlLinksEntityProducer entity = new XmlLinksEntityProducer(properties);
final EntityInfoAggregator entityInfo = EntityInfoAggregator.create(entitySet, properties.getExpandSelectTree());
entity.append(writer, entityInfo, data);
writer.flush();
csb.closeWrite();
return ODataResponse.entity(csb.getInputStream()).build();