private Object toLazyUnionObject(Object obj, ObjectInspector objectInspector) {
    if (obj == null) {
      return null;
    }

    if (!(objectInspector instanceof LazyUnionObjectInspector)) {
      throw new IllegalArgumentException(
          "Invalid objectinspector found. Expected LazyUnionObjectInspector, Found "
              + objectInspector.getClass());
    }

    StandardUnion standardUnion = (StandardUnion) obj;
    LazyUnionObjectInspector lazyUnionOI = (LazyUnionObjectInspector) objectInspector;

    // Grab the tag and the field
    byte tag = standardUnion.getTag();
    Object field = standardUnion.getObject();

    ObjectInspector fieldOI = lazyUnionOI.getObjectInspectors().get(tag);

    // convert to lazy object
    Object convertedObj = null;

    if (field != null) {
      convertedObj = toLazyObject(field, fieldOI);
    }

    if (convertedObj == null) {
      return null;
    }

    return new LazyUnion(lazyUnionOI, tag, convertedObj);
  }
Convert the given object to a lazy object using the given {@link ObjectInspector}

@param obj Object to be converted to a {@link LazyObject}
@param objectInspector ObjectInspector used for the conversion
@return the created {@link LazyObject lazy object}
serde/src/java/org/apache/hadoop/hive/serde2/avro/AvroLazyObjectInspector.java