The name and namespace is part of any named schema (Type.RECORD, Type.FIXED, 
Type.ENUM).

We don't currently have an API to search a schema for subschemas that match 
names.  It would be useful, you might want to create a JIRA ticket explaining 
your use case.

So it would be a little more complex.

        Schema schema = Schema.parse(schemaDescription);
        Schema.Type type = schema.getType();
        switch (type) {
        case RECORD:
          String name = schema.getName();
          String namespace = schema.getNamespace();
          List<Field> fields = schema.getFields();
        }

        etc.

In general, I have created SpecificRecord objects from schemas using the 
specific compiler (and the ant task or maven plugin) and then within those 
generated classes there is a static SCHEMA variable to reference.

Avro IDL is alo an easier way to define related schemas.  Currently there are 
only build tools that generate code from these, though there are APIs to 
extract schemas.

-Scott

On 7/13/11 10:43 AM, "Peter Wolf" <opus...@gmail.com<mailto:opus...@gmail.com>> 
wrote:

Hello, this a dumb question, but I can not find the answer in the docs

I want to have a complicated schema with lots of Records referencing other 
Records.

Like this...

{
  "namespace": "com.foobah",
  "name": "Bah",
  "type": "record",
  "fields": [
  {"name": "value", "type": "int"}
  ]
}

{
  "namespace": "com.foobah",
  "name": "Foo",
  "type": "record",
  "fields": [
  {"name": "bah", "type": "Bah"}
  ]
}
Using the Java API, how do I reference types within a schema?  Let's say I want 
to make a Foo object, I want to do something like this...

        Schema schema = Schema.parse(schemaDescription);
>>> Schema foo = schema.getSchema("com.foobah.Foo"); <<<
        GenericData o = new GenericData( foo );

Many thanks in advance
Peter



Reply via email to