avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Doug Cutting <cutt...@apache.org>
Subject Re: Avro 1.7.6 Enums with fields
Date Fri, 07 Mar 2014 19:00:01 GMT
You can add attributes to the schema, e.g.:

{"type":"enum", "name":"MyEnum",
 "symbols":["FOO", "BAR", "BAZ"],
 "indexes":[10,11,12],
 "descriptions"["foo is...", "bar is..", "baz is"]
}

Then, if you generate specific code, you can access this with something like:

int fooIndex = MyEnum.getClassSchema().getJsonProp("indexes").get(FOO.ordinal()).getIntValue();

Doug

On Wed, Mar 5, 2014 at 8:45 PM, Daniel Jue <teamphy6@gmail.com> wrote:
> Hi, I'm kind of new to Avro, and I couldn't find an example on this by
> googling.  I have a Java enum that looks like this:
>
> public enum G_CanonicalPropertyType {
> FOO(10, "Foo", "foo is not food"),
> BAR(11, "Bar", "bar is like a snickers"),
> BAZ(12, "Baz", "baz is a widget with wings");
>
> private int index;
> private String friendlyName;
> private String description;
>  //then constructor and getters
> }
>
> Where the fields for each enum are important (there are also getters and
> setters for them)
>
> I'm trying to write an Avro avdl version of this, what's the best way?
>
> Thanks,
>
> Dan

Mime
View raw message