private Schema read(JsonReader reader, Set<String> knownRecords) throws IOException {
    JsonToken token = reader.peek();
    switch (token) {
      case NULL:
        return null;
      case STRING: {
        // Simple type or know record type
        String name = reader.nextString();
        if (knownRecords.contains(name)) {
          return Schema.recordOf(name);
        }
        return Schema.of(Schema.Type.valueOf(name.toUpperCase()));
      }
      case BEGIN_ARRAY:
        // Union type
        return readUnion(reader, knownRecords);
      case BEGIN_OBJECT: {
        reader.beginObject();
        String name = reader.nextName();
        if (!"type".equals(name)) {
          throw new IOException("Property \"type\" missing.");
        }
        Schema.Type schemaType = Schema.Type.valueOf(reader.nextString().toUpperCase());

        Schema schema;
        switch (schemaType) {
          case ENUM:
            schema = readEnum(reader);
            break;
          case ARRAY:
            schema = readArray(reader, knownRecords);
            break;
          case MAP:
            schema = readMap(reader, knownRecords);
            break;
          case RECORD:
            schema = readRecord(reader, knownRecords);
            break;
          default:
            schema = Schema.of(schemaType);
        }
        reader.endObject();
        return schema;
      }
    }
    throw new IOException("Malformed schema input.");
  }
private Schema read ( JsonReader reader , Set < String > knownRecords ) throws IOException { JsonToken token = reader . peek ( ) ; switch ( token ) { case NULL : return null ; case STRING : { String name = reader . nextString ( ) ; if ( knownRecords . contains ( name ) ) { return Schema . recordOf ( name ) ; } return Schema . of ( Schema . Type . valueOf ( name . toUpperCase ( ) ) ) ; } case BEGIN_ARRAY : return readUnion ( reader , knownRecords ) ; case BEGIN_OBJECT : { reader . beginObject ( ) ; String name = reader . nextName ( ) ; if ( ! "type" . equals ( name ) ) { throw new IOException ( "Property \"type\" missing." ) ; } Schema . Type schemaType = Schema . Type . valueOf ( reader . nextString ( ) . toUpperCase ( ) ) ; Schema schema ; switch ( schemaType ) { case ENUM : schema = readEnum ( reader ) ; break ; case ARRAY : schema = readArray ( reader , knownRecords ) ; break ; case MAP : schema = readMap ( reader , knownRecords ) ; break ; case RECORD : schema = readRecord ( reader , knownRecords ) ; break ; default : schema = Schema . of ( schemaType ) ; } reader . endObject ( ) ; return schema ; } } throw new IOException ( "Malformed schema input." ) ; }
Reads json value and convert it into {@link Schema} object.

@param reader Source of json
@param knownRecords Set of record name already encountered during the reading.
@return A {@link Schema} reflecting the json.
@throws java.io.IOException Any error during reading.