use of jakarta.json.stream.JsonLocation in project avro-util by linkedin.
the class JsonReaderWithLocations method readJsonValueInternal.
protected JsonValueExt readJsonValueInternal() {
JsonLocation endLocation;
switch(currentEvent) {
case START_ARRAY:
return readJsonArrayInternal();
case START_OBJECT:
return readObjectInternal();
case KEY_NAME:
throw new JsonException("unexpected " + currentEvent + " at " + parser.getLocation());
case VALUE_STRING:
String str = parser.getString();
endLocation = parser.getLocation();
return new JsonStringExtImpl(source, JsonPUtil.subtract(endLocation, str.length()), endLocation, str);
case VALUE_NUMBER:
// we dont bother optimizing for ints/longs
return new JsonNumberExtImpl(source, parser.getLocation(), parser.getLocation(), parser.getBigDecimal());
case VALUE_TRUE:
endLocation = parser.getLocation();
return new JsonTrueExtImpl(source, JsonPUtil.subtract(endLocation, 4), endLocation);
case VALUE_FALSE:
endLocation = parser.getLocation();
return new JsonFalseExtImpl(source, JsonPUtil.subtract(endLocation, 5), endLocation);
case VALUE_NULL:
endLocation = parser.getLocation();
return new JsonNullExtImpl(source, JsonPUtil.subtract(endLocation, 4), endLocation);
case END_ARRAY:
throw new JsonException("unexpected " + currentEvent + " at " + parser.getLocation());
case END_OBJECT:
throw new JsonException("unexpected " + currentEvent + " at " + parser.getLocation());
default:
throw new JsonException("unexpected " + currentEvent + " at " + parser.getLocation());
}
}
use of jakarta.json.stream.JsonLocation 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