Using FastInfoset with JAXB
FastInfoset implementats SAX and StAX interfaces. This allows any XML technologies to be used with FastInfoset provided that they support either SAX or StAX. So it's generally that easy.
For example, the following code creates a StAX XMLStreamReader from a file encoded in the FastInfoset format:
InputStream in = new BufferedInputStream(new FileInputStream(...));
XMLStreamReader streamReader = new StAXDocumentParser(in);
So you can just pass this in to the unmarshaller to unmarshal this into JAXB objects:
JAXBContext context = JAXBContext.newInstance(...);
Unmarshaller u = context.createUnmarshaller();
Object jaxbObject = u.unmarshal(streamReader);
Similarly, to marshal JAXB objects into FastInfoset, first create StAX XMLStreamWriter for FastInfoset like this:
BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream(...));
StAXDocumentSerializer sw = new StAXDocumentSerializer();
Since StAXDocumentSerializer implements XMLStreamWriter, you can then just pass this writer to a JAXB marshaller:
Marshaller m = context.createMarshaller();
As I mentioned before, this technology works with any XML technologies, not just JAXB. So FastInfoset is really very easy to use.
That said, starting with a recent version of the JAXB RI, the RI internally recognizes that it's writing to FastInfoset, and it takes an optimized codepath just for FastInfoset. This gives you more performance boost without any work on your side. So it's not only fast, but it's also easy.