code: private void encodeUnion(GeneratorAdapter mg, TypeToken<?> outputType, Schema schema,
                             int value, int encoder, int schemaLocal, int seenRefs) {
      Label nullLabel = mg.newLabel();
      Label endLabel = mg.newLabel();
      mg.loadArg(value);
  
      mg.ifNull(nullLabel);
      // Not null, write out 0 and then encode the value
      encodeInt(mg, 0, encoder);
  
      mg.loadThis();
      mg.loadArg(value);
      doCast(mg, outputType, schema.getUnionSchema(0));
      mg.loadArg(encoder);
      mg.loadArg(schemaLocal);
      mg.push(0);
      mg.invokeVirtual(Type.getType(Schema.class), getMethod(Schema.class, "getUnionSchema", int.class));
      mg.loadArg(seenRefs);
      mg.invokeVirtual(classType, getEncodeMethod(outputType, schema.getUnionSchema(0)));
  
      mg.goTo(endLabel);
  
      mg.mark(nullLabel);
      // Null, write out 1
      encodeInt(mg, 1, encoder);
      mg.mark(endLabel);
    }
docs: Generates method body for encoding union schema. Union schema is used for representing object references that
  could be {@code null}.
  @param mg
  @param outputType
  @param schema
  @param value
  @param encoder
  @param schemaLocal
  @param seenRefs