GenericRecord metadata1 = avroDecoder.getMetadata(e, null);
Schema pschema = Schema.createUnion(Arrays.asList(avroDecoder.getPayloadSchema(e).getSchema(),
Schema.create(Type.NULL)));
Field pfield = new Field("payload", pschema, "payload", null);
VersionedSchema metaschema = avroDecoder.getMetadataSchema(e);
Schema mschema = null != metaschema ?
Schema.createUnion(Arrays.asList(metaschema.getSchema(), Schema.create(Type.NULL))) :
Schema.createUnion(Arrays.asList(Schema.create(Type.INT), Schema.create(Type.NULL)));
Field mfield = new Field("metadata", mschema, "metadata", null);
Schema combined = Schema.createRecord(Arrays.asList(pfield, mfield));
GenericRecord r = new GenericData.Record(combined);
r.put(0, payload1);