@SuppressWarnings("unchecked") @Override public void encode(RawUnionValue union, OutputStream outStream, Context context) throws IOException, CoderException { int index = getIndexForEncoding(union); // Write out the union tag. VarInt.encode(index, outStream); // Write out the actual value. Coder<Object> coder = (Coder<Object>) elementCoders.get(index); coder.encode(union.getValue(), outStream, context); }