use of com.linkedin.avroutil1.parser.jsonpext.JsonReaderExt in project avro-util by linkedin.
the class AvscParser method parse.
public AvscParseResult parse(String avsc) {
JsonReaderExt jsonReader = new JsonReaderWithLocations(new StringReader(avsc), null);
JsonObjectExt root;
AvscFileParseContext context = new AvscFileParseContext(avsc);
AvscParseResult result = new AvscParseResult();
try {
root = jsonReader.readObject();
} catch (JsonParsingException e) {
Throwable rootCause = Util.rootCause(e);
String message = rootCause.getMessage();
if (message != null && message.startsWith("Unexpected char 47")) {
// 47 is ascii for '/' (utf-8 matches ascii on "low" characters). we are going to assume this means
// someone tried putting a //comment into an avsc source
result.recordError(new JsonParseException("comments not supported in json at" + e.getLocation(), e));
} else {
result.recordError(new JsonParseException("json parse error at " + e.getLocation(), e));
}
return result;
} catch (Exception e) {
result.recordError(new JsonParseException("unknown json parse error", e));
return result;
}
try {
parseSchemaDeclOrRef(root, context, true);
context.resolveReferences();
result.recordParseComplete(context);
} catch (Exception parseIssue) {
result.recordError(parseIssue);
}
return result;
}
use of com.linkedin.avroutil1.parser.jsonpext.JsonReaderExt in project avro-util by linkedin.
the class TestJsonParsing method testSimpleSchema.
@Test
public void testSimpleSchema() throws Exception {
String avsc = TestUtil.load("schemas/TestRecord.avsc");
JsonReader referenceReader = Json.createReader(new StringReader(avsc));
JsonObject referenceObject = referenceReader.readObject();
JsonReaderExt ourReader = new JsonReaderWithLocations(new StringReader(avsc), null);
JsonObjectExt ourObject = ourReader.readObject();
// assert we read everything correctly. our equals() implementations are not
// commutative with regular json-p objects (yet?)
// noinspection SimplifiableAssertion
Assert.assertTrue(referenceObject.equals(ourObject));
// see that we have text locations for json values
JsonValueExt fields = ourObject.get("fields");
JsonLocation startLocation = fields.getStartLocation();
JsonLocation endLocation = fields.getEndLocation();
Assert.assertEquals(startLocation.getLineNumber(), 6);
Assert.assertEquals(endLocation.getLineNumber(), 70);
}
Aggregations