case MAP:
case ARRAY:
case RECORD:
byte[] data = null;
try {
@SuppressWarnings("rawtypes")
SpecificDatumWriter writer = getDatumWriter(fieldSchema.getFullName(),
fieldSchema);
data = IOUtils.serialize(writer, fieldSchema, fieldValue);
} catch (IOException e) {
LOG.error(e.getMessage(), e.getStackTrace().toString());
}
fieldValue = data;
break;
case BYTES:
fieldValue = ((ByteBuffer) fieldValue).array();
break;
case ENUM:
case STRING:
fieldValue = fieldValue.toString();
break;
case UNION:
// If field's schema is null and one type, we do undertake serialization.
// All other types are serialized.
if (fieldSchema.getTypes().size() == 2 && isNullable(fieldSchema)) {
int schemaPos = getUnionSchema(fieldValue, fieldSchema);
Schema unionSchema = fieldSchema.getTypes().get(schemaPos);
fieldValue = serializeFieldValue(unionSchema, fieldValue);
} else {
byte[] serilazeData = null;
try {
@SuppressWarnings("rawtypes")
SpecificDatumWriter writer = getDatumWriter(
String.valueOf(fieldSchema.hashCode()), fieldSchema);
serilazeData = IOUtils.serialize(writer, fieldSchema, fieldValue);
} catch (IOException e) {
LOG.error(e.getMessage(), e.getStackTrace().toString());