### Question:
CSVSerde extends AbstractSerDe { @Override public Writable serialize(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."); } try { for (int c = 0; c < numCols; c++) { final Object field = outputRowOI.getStructFieldData(obj, outputFieldRefs.get(c)); ObjectInspector fieldOI = outputFieldRefs.get(c).getFieldObjectInspector(); outputFields[c] = serializeField(field, fieldOI); } final StringWriter writer = new StringWriter(); final CSVWriter csv = newWriter(writer, separatorChar, quoteChar, escapeChar); csv.writeNext(outputFields); csv.close(); return new Text(writer.toString()); } catch (final IOException ioe) { throw new SerDeException(ioe); } }  @Override void initialize(final Configuration conf, final Properties tbl); @Override Writable serialize(Object obj, ObjectInspector objInspector); @Override Object deserialize(final Writable blob); @Override ObjectInspector getObjectInspector(); @Override Class<? extends Writable> getSerializedClass(); @Override SerDeStats getSerDeStats(); static final String DEFAULT_NULL_FORMAT; static final char DEFAULT_COLLECTION_SEPERATOR; static final char DEFAULT_STRUCT_FIELD_SEPERATOR; static final char DEFAULT_UNION_TAG_FIELD_SEPERATOR; static final char DEFAULT_MAP_KEY_VALUE_SEPERATOR; }### Answer:
@Test public void testSerialize() throws Exception { props.put("separatorChar", ","); props.put("quoteChar", "\""); props.put(serdeConstants.LIST_COLUMNS, "a,b,c,d"); props.put(serdeConstants.LIST_COLUMN_TYPES, "string,varchar(20),int,char(10)"); csv.initialize(null, props); List<? extends Object> row = Arrays.asList("hello", "yes, okay", 1, "char"); Object ser = csv.serialize(row, csv.getObjectInspector()); Assert.assertEquals(((Text) ser).toString(), "\"hello\",\"yes, okay\",\"1\",\"char\""); row = Arrays.asList("hello", null, 1, "char"); ser = csv.serialize(row, csv.getObjectInspector()); Assert.assertEquals(((Text) ser).toString(), "\"hello\",\"NULL\",\"1\",\"char\""); props.put(serdeConstants.LIST_COLUMNS, "a,b,c,d,e,f,g"); props.put(serdeConstants.LIST_COLUMN_TYPES, "string,varchar(20),int,char(10),array<int>,map<int,string>,struct<a:int,b:map<int,string>>"); csv.initialize(null, props); Map<Integer, String> map = new LinkedHashMap<Integer, String>(); map.put(5, "five"); map.put(null, "six"); map.put(7, null); row = Arrays.asList("hello", "yes, okay", 1, "char", Arrays.asList(1, null, 3), map, Arrays.asList(8, map)); ser = csv.serialize(row, csv.getObjectInspector()); Assert.assertEquals(((Text) ser).toString(), "\"hello\",\"yes, okay\",\"1\"," + "\"char\",\"1,NULL,3\",\"5=five,NULL=six,7=NULL\",\"8:5=five,NULL=six,7=NULL\""); props.put(serdeConstants.LIST_COLUMNS, "a,b,c,d"); props.put(serdeConstants.LIST_COLUMN_TYPES, "string,varchar(20),int,char(10)"); }