XmlCodec implements MsgCodec { @Override public void encode(Object group, OutputStream out) throws IOException { Object groupType = groupTypeAccessor.getGroupType(group); StaticGroupValue groupInstr = staticGroupsByGroupType.get(groupType); if (groupInstr == null) { GroupDef groupDef = schema.getGroup((Object)groupType); groupInstr = groupDef != null ? staticGroupsByName.get(groupDef.getName()) : null; if (groupInstr == null) { throw new IllegalArgumentException("Unknown Java class: " + group.getClass()); } } PrintWriter writer = new PrintWriter(new OutputStreamWriter(out, UTF8)); groupInstr.writeElementValue(group, determineGroupClass(group), groupInstr.getNsName(), writer); writer.flush(); } 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 = IllegalArgumentException.class) public void testEncodeHelloMissingField() 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.encode(new Hello(), new ByteArrayOutputStream()); }