XmlCodec implements MsgCodec { @Override public Object decode(InputStream in) throws IOException { try { saxParser.parse(in, saxHandler); return saxHandler.getValue(); } catch (SAXException e) { throw new DecodeException(e); } } XmlCodec(Schema schema); @Override void encode(Object group, OutputStream out); @Override Object decode(InputStream in); @Override void encode(Object group, ByteSink out); @Override Object decode(ByteSource in);  }
@Test(expected = DecodeException.class) public void testDecodeHelloMissingField() throws Exception { Schema schema = new SchemaBuilder().build(Hello.class); Annotations annot = new Annotations(); annot.path("Hello", "greeting").put("xml:field", "element"); schema = schema.replaceAnnotations(annot); MsgCodec codec = new XmlCodec(schema); codec.decode(new ByteArrayInputStream("<hello/>".getBytes("UTF-8"))); }
@Test(expected = DecodeException.class) public void testFailDecodeAbstractMessage() throws Exception { Schema schema = new SchemaBuilder().build(AbstractMessage.class); XmlCodec codec = new XmlCodec(schema); String xml = "<AbstractMessage/>"; ByteArrayInputStream in = new ByteArrayInputStream(xml.getBytes(Charset.forName("UTF8"))); codec.decode(in); }