title: How to serialize an Java Object in Hadoop?
body: <p>Object should implement <code>Writable</code> interface in order to be serialized when transmitted in Hadoop. Take the Lucene <code>ScoreDoc</code> class as an example:</p>
  
  <pre><code>public class ScoreDoc implements java.io.Serializable {
  
    /** The score of this document for the query. */
    public float score;
  
    /** Expert: A hit document's number.
     * @see Searcher#doc(int) */
    public int doc;
  
    /** Only set by {@link TopDocs#merge} */
    public int shardIndex;
  
    /** Constructs a ScoreDoc. */
    public ScoreDoc(int doc, float score) {
      this(doc, score, -1);
    }
  
    /** Constructs a ScoreDoc. */
    public ScoreDoc(int doc, float score, int shardIndex) {
      this.doc = doc;
      this.score = score;
      this.shardIndex = shardIndex;
    }
  
    // A convenience method for debugging.
    @Override
    public String toString() {
      return "doc=" + doc + " score=" + score + " shardIndex=" + shardIndex;
    }
  }
  </code></pre>
  
  <p>How should I serialize it with <code>Writable</code> interface? What is the connection between <code>Writable</code> and <code>java.io.serializable</code> interface?</p>