code: @Override
    @SuppressWarnings("unchecked")
    public W toWritable(Object value) throws IOException {
      if (value == null) {
        return null;
      }
      // route to appropriate method using Pig data type
      switch (DataType.findType(value)) {
        case DataType.BYTEARRAY:
          return toWritable((DataByteArray) value);
        case DataType.CHARARRAY:
          return toWritable((String) value);
        case DataType.INTEGER:
          return toWritable((Integer) value);
        case DataType.LONG:
          return toWritable((Long) value);
        case DataType.FLOAT:
          return toWritable((Float) value);
        case DataType.DOUBLE:
          return toWritable((Double) value);
        case DataType.MAP:
          return toWritable((Map<String, Object>) value);
        case DataType.TUPLE:
          return toWritable((Tuple) value);
        case DataType.BAG:
          return toWritable((DataBag) value);
        default:
          throw new IOException("Pig value class '" + value.getClass().getName() + "' is unsupported");
      }
    }
docs: Default implementation routes to one of the other {@code toWritable} methods based on the type
  of the input Pig value.
  
  @see WritableConverter#toWritable(java.lang.Object, org.apache.hadoop.io.Writable)