@SuppressWarnings("unchecked")
  @Override
  public void readFields(DataInput in) throws IOException {
    super.readFields(in);

    // First clear the map. Otherwise we will just accumulate
    // entries every time this method is called.
    this.instance.clear();

    // Read the number of entries in the map

    int entries = in.readInt();

    // Then read each key/value pair

    for (int i = 0; i < entries; i++) {
      Writable key = (Writable) ReflectionUtils.newInstance(getClass(in.readByte()), getConf());

      key.readFields(in);

      Writable value = (Writable) ReflectionUtils.newInstance(getClass(in.readByte()), getConf());

      value.readFields(in);
      instance.put(key, value);
    }
  }
  @Override
  public void write(DataOutput out) throws IOException {
    super.write(out);

    // Write out the number of entries in the map

    out.writeInt(instance.size());

    // Then write out each key/value pair

    for (Map.Entry<Writable, Writable> e : instance.entrySet()) {
      out.writeByte(getId(e.getKey().getClass()));
      e.getKey().write(out);
      out.writeByte(getId(e.getValue().getClass()));
      e.getValue().write(out);
    }
  }