2012-12-14 40 views

回答

8

您可以編寫自定義類型,您可以將其作爲映射器值發出。但是無論您想要發佈什麼值,都必須實現可寫接口。你可以這樣做:

public class MyObj implements WritableComparable<MyObj>{ 

    private String date; 
    private Double balance; 

    public String getDate() { return date;} 
    public Double getBalance() { return balance;} 

    @Override 
    public void readFields(DataInput in) throws IOException { 

     //Define how you want to read the fields 
     } 
    @Override 
    public void writeFields(DataOutput out) throws IOException { 

     //Define how you want to write the fields 
    } 
     ....... 
     ....... 
     ....... 

} 

或者你可以使用Avro序列化框架。

相關問題