avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Doug Cutting <cutt...@apache.org>
Subject Re: How to reference previously defined enum in avsc file?
Date Fri, 11 Mar 2011 18:59:44 GMT
On 03/11/2011 10:28 AM, Scott Carey wrote:
> You need an array of JSON objects in the avsc file, something like:

An .avsc file can only contain a single top-level JSON object, not an
array.  So, if you wanted to define this in an .avsc file then you'd
need to use a nested definition, like:

------------

{
    "namespace": "def.note.pad",
    "type": "record",
    "name": "Page",
    "doc": "Object definition of a Page composed of alphabet",
    "fields": [
        {
            "name": "letter",
            "type": {
                "type": "enum",
                "namespace": "def.al.pha.bet",
                "name": "KnownLetters",
                "doc": "Specifies known types of letters",
                "symbols": ["A", "B", "C", "D", "E"]
            }
        }
    ]
}

-------------

Or you can use a .avpr file to define dependent types, like:

-------------
{   "protocol": "Foo",
    "namespace": "def.al.pha.bet",
    "types": [
        {
            "type": "enum",
            "name": "KnownLetters",
            "doc": "Specifies known types of letters",
            "symbols": ["A", "B", "C", "D", "E"]
        },
        {
            "namespace": "def.note.pad",
            "type": "record",
            "name": "Page",
            "doc": "Object definition of a Page composed of alphabet",
            "fields": [
                {"name": "letter",  "type": "KnownLetters"}
            ]
        }
    ]
}
------------

Doug

Mime
View raw message