/** * Parse data schema in JSON format to obtain a {@link DataSchema}. * * @param schemaText provides the data schema in JSON format. * @param schemaResolver for resolving referenced schemas * @return the {@link DataSchema} parsed from the data schema in JSON format. * @throws IllegalArgumentException if the data schema in JSON format is invalid or * there is more than one top level schema. */ public static DataSchema parseSchema(String schemaText, DataSchemaResolver schemaResolver) throws IllegalArgumentException { PegasusSchemaParser parser = SchemaParserFactory.instance().create(schemaResolver); parser.parse(schemaText); if (parser.hasError()) { if (debug) { out.println(parser.errorMessage()); } throw new IllegalArgumentException(parser.errorMessage()); } if (parser.topLevelDataSchemas().size() != 1) { throw new IllegalArgumentException("More than one top level schemas"); } return parser.topLevelDataSchemas().get(0); }
getMessage().append(parser.errorMessage());
if (parser.hasError()) throw new IllegalArgumentException(parser.errorMessage());