@Override
  public Writable doSerialize(Object obj, ObjectInspector objInspector) throws SerDeException {
    final StructObjectInspector outputRowOI = (StructObjectInspector) objInspector;
    final List<? extends StructField> outputFieldRefs = outputRowOI.getAllStructFieldRefs();

    if (outputFieldRefs.size() != numCols) {
      throw new SerDeException("Cannot serialize the object because there are "
              + outputFieldRefs.size() + " fields but the table has " + numCols + " columns.");
    }

    // Get all data out.
    for (int c = 0; c < numCols; c++) {
      final Object field = outputRowOI.getStructFieldData(obj, outputFieldRefs.get(c));
      final ObjectInspector fieldOI = outputFieldRefs.get(c).getFieldObjectInspector();

      // Convert the field to Java class String, because objects of String type
      // can be stored in String, Text, or some other classes.
      if (fieldOI instanceof StringObjectInspector) {
        outputFields[c] = ((StringObjectInspector) fieldOI).getPrimitiveJavaObject(field);
      } else if (fieldOI instanceof AbstractPrimitiveWritableObjectInspector) {
        Object primitiveJavaObject = ((AbstractPrimitiveWritableObjectInspector) fieldOI).getPrimitiveJavaObject(field);
        outputFields[c] = Objects.toString(primitiveJavaObject, null);
      } else {
        throw new UnsupportedOperationException(
            "Column type of " + fieldOI.getTypeName() + " is not supported with OpenCSVSerde");
      }
    }

    final StringWriter writer = new StringWriter();
    final CSVWriter csv = newWriter(writer, separatorChar, quoteChar, escapeChar);

    try {
      csv.writeNext(outputFields, applyQuotesToAll);
      csv.close();

      return new Text(writer.toString());
    } catch (final IOException ioe) {
      throw new SerDeException(ioe);
    }
  }
OpenCSVSerde use opencsv to deserialize CSV format.
Users can specify custom separator, quote or escape characters. And the default separator(\),
quote("), and escape characters(\) are the same as the opencsv library.
serde/src/java/org/apache/hadoop/hive/serde2/OpenCSVSerde.java