Как сериализовать объект Java в Hadoop?
Объект должен реализоватьWritable
интерфейс для того, чтобы быть сериализованным при передаче в Hadoop. Возьми LuceneScoreDoc
класс в качестве примера:
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;
}
}
Как я должен сериализовать это сWritable
интерфейс? Какая связь междуWritable
а такжеjava.io.serializable
интерфейс?