2015-08-13 54 views

回答

3

所有字段默認情況下需要的Avro。由於是官方文檔中mentioned,如果你想使一些可選的,你必須使它可爲空的unioning其類型與null,這樣

{ "namespace": "example.avro", 
    "type": "record", 
    "name": "User", 
    "fields": [ 
    {"name": "name", "type": "string"}, 
    {"name": "favorite_number", "type": ["int", "null"]}, 
    {"name": "favorite_color", "type": ["string", "null"]} 
    ] 
} 

在這個例子中,name是必需的,favorite_numberfavorite_color是可選的。我建議在文檔上多花點時間。

+0

它只要可以作爲兩個領域favorite_number和favorite_color有值「空」,但如果系列化分別我把int或字符串失敗。在下面看我的問題,我演示它... –