private Schema readRecord(JsonReader reader, Set<String> knownRecords) throws IOException {
    if (!"name".equals(reader.nextName())) {
      throw new IOException("Property \"name\" missing for record.");
    }

    String recordName = reader.nextString();

    // Read in fields schemas
    if (!"fields".equals(reader.nextName())) {
      throw new IOException("Property \"fields\" missing for record.");
    }

    knownRecords.add(recordName);

    ImmutableList.Builder<Schema.Field> fieldBuilder = ImmutableList.builder();
    reader.beginArray();
    while (reader.peek() != JsonToken.END_ARRAY) {
      reader.beginObject();
      if (!"name".equals(reader.nextName())) {
        throw new IOException("Property \"name\" missing for record field.");
      }
      String fieldName = reader.nextString();
      fieldBuilder.add(Schema.Field.of(fieldName, readInnerSchema(reader, "type", knownRecords)));
      reader.endObject();
    }
    reader.endArray();
    return Schema.recordOf(recordName, fieldBuilder.build());
  }
private Schema readRecord ( JsonReader reader , Set < String > knownRecords ) throws IOException { if ( ! "name" . equals ( reader . nextName ( ) ) ) { throw new IOException ( "Property \"name\" missing for record." ) ; } String recordName = reader . nextString ( ) ; if ( ! "fields" . equals ( reader . nextName ( ) ) ) { throw new IOException ( "Property \"fields\" missing for record." ) ; } knownRecords . add ( recordName ) ; ImmutableList . Builder < Schema . Field > fieldBuilder = ImmutableList . builder ( ) ; reader . beginArray ( ) ; while ( reader . peek ( ) != JsonToken . END_ARRAY ) { reader . beginObject ( ) ; if ( ! "name" . equals ( reader . nextName ( ) ) ) { throw new IOException ( "Property \"name\" missing for record field." ) ; } String fieldName = reader . nextString ( ) ; fieldBuilder . add ( Schema . Field . of ( fieldName , readInnerSchema ( reader , "type" , knownRecords ) ) ) ; reader . endObject ( ) ; } reader . endArray ( ) ; return Schema . recordOf ( recordName , fieldBuilder . build ( ) ) ; }
Constructs {@link Schema.Type#RECORD RECORD} type schema from the json input.

@param reader The {@link JsonReader} for streaming json input tokens.
@param knownRecords Set of record name already encountered during the reading.
@return A {@link Schema} of type {@link Schema.Type#RECORD RECORD}.
@throws java.io.IOException When fails to construct a valid schema from the input.