public static Object toThriftPayload(Object val, ObjectInspector valOI, int version) {
    if (valOI.getCategory() == ObjectInspector.Category.PRIMITIVE) {
      if (val == null) {
        return null;
      }
      Object obj = ObjectInspectorUtils.copyToStandardObject(val, valOI,
          ObjectInspectorUtils.ObjectInspectorCopyOption.JAVA);
      // uses string type for binary before HIVE_CLI_SERVICE_PROTOCOL_V6
      if (version < 5 && ((PrimitiveObjectInspector)valOI).getPrimitiveCategory() ==
          PrimitiveObjectInspector.PrimitiveCategory.BINARY) {
        // todo HIVE-5269
        return new String((byte[])obj);
      }
      return obj;
    }
    // for now, expose non-primitive as a string
    // TODO: expose non-primitive as a structured object while maintaining JDBC compliance
    return SerDeUtils.getJSONString(val, valOI);
  }
Convert a Object to a standard Java object in compliance with JDBC 3.0 (see JDBC 3.0
Specification, Table B-3: Mapping from JDBC Types to Java Object Types).

This method is kept consistent with HiveResultSetMetaData#hiveTypeToSqlType .
serde/src/java/org/apache/hadoop/hive/serde2/SerDeUtils.java