JsonCodec implements MsgCodec { @Override public void encode(Object group, OutputStream out) throws IOException { if (group == null) { out.write(NULL_BYTES); } else { JsonFactory f = new JsonFactory(); JsonGenerator g = f.createGenerator(out); dynamicGroupHandler.writeValue(group, g); g.flush(); } } @SuppressWarnings("rawtypes")  JsonCodec(Schema schema, boolean jsSafe); JsonValueHandler<?> getValueHandler(String groupName, String ... fieldNames); @Override void encode(Object group, OutputStream out); @Override void encode(Object group, ByteSink out); void encodeStatic(Object group, OutputStream out); void encodeStatic(Object group, ByteSink out); @Override Object decode(InputStream in); @Override Object decode(ByteSource in); Object decodeStatic(Object groupType, InputStream in); Object decodeStatic(Object groupType, ByteSource in); Object decodeStatic(String groupName, InputStream in); Object decodeStatic(String groupName, ByteSource in);  }
@Test(expected = IllegalArgumentException.class) public void testEncodeMissingRequiredField() throws IOException { SchemaBuilder builder = new SchemaBuilder(); Schema schema = builder.build(Hello.class); MsgCodec codec = new JsonCodec(schema, false); ByteArrayOutputStream out = new ByteArrayOutputStream(); Hello msg = new Hello(null); codec.encode(msg, out); }