class TemplateSerializer {

    public static byte[] serialize(final TemplateDTO dto) {
        try {
            final ByteArrayOutputStream baos = new ByteArrayOutputStream();
            final BufferedOutputStream bos = new BufferedOutputStream(baos);

            final Marshaller marshaller = jaxbContext.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
            marshaller.marshal(dto, bos);

            bos.flush();
            return baos.toByteArray(); //Note: For really large templates this could use a lot of heap space
        } catch (final IOException | JAXBException e) {
            throw new FlowSerializationException(e);
        }
    }

}