use of com.linkedin.avroutil1.parser.jsonpext.JsonObjectExt in project avro-util by linkedin.
the class AvscParser method parseExtraProps.
private LinkedHashMap<String, JsonValueExt> parseExtraProps(JsonObjectExt field, Set<String> toIgnore) {
LinkedHashMap<String, JsonValueExt> results = new LinkedHashMap<>(3);
for (Map.Entry<String, JsonValue> entry : field.entrySet()) {
// doc says there are in the order they are in json
String propName = entry.getKey();
if (toIgnore.contains(propName)) {
continue;
}
JsonValueExt propValue = (JsonValueExt) entry.getValue();
results.put(propName, propValue);
}
return results;
}
use of com.linkedin.avroutil1.parser.jsonpext.JsonObjectExt 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);
}
use of com.linkedin.avroutil1.parser.jsonpext.JsonObjectExt in project avro-util by linkedin.
the class AvscParser method parseCollectionSchema.
private AvroCollectionSchema parseCollectionSchema(JsonObjectExt objectNode, AvscFileParseContext context, AvroType avroType, CodeLocation codeLocation, JsonPropertiesContainer props) {
switch(avroType) {
case ARRAY:
JsonValueExt arrayItemsNode = getRequiredNode(objectNode, "items", () -> "array declarations must have an items property");
SchemaOrRef arrayItemSchema = parseSchemaDeclOrRef(arrayItemsNode, context, false);
return new AvroArraySchema(codeLocation, arrayItemSchema, props);
case MAP:
JsonValueExt mapValuesNode = getRequiredNode(objectNode, "values", () -> "map declarations must have a values property");
SchemaOrRef mapValueSchema = parseSchemaDeclOrRef(mapValuesNode, context, false);
return new AvroMapSchema(codeLocation, mapValueSchema, props);
default:
throw new IllegalStateException("unhandled: " + avroType + " for object at " + codeLocation.getStart());
}
}
use of com.linkedin.avroutil1.parser.jsonpext.JsonObjectExt in project avro-util by linkedin.
the class AvscParser method parseStringRepresentation.
private Parsed<AvroJavaStringRepresentation> parseStringRepresentation(// type declaration node
JsonObjectExt objectNode, AvscFileParseContext context, AvroType avroType, CodeLocation codeLocation) {
Parsed<AvroJavaStringRepresentation> result = new Parsed<>();
Located<String> repStr = getOptionalString(objectNode, "avro.java.string");
AvroJavaStringRepresentation representation;
if (repStr != null) {
representation = AvroJavaStringRepresentation.fromJson(repStr.getValue());
if (representation != null) {
result.setData(representation);
} else {
result.recordIssue(AvscIssues.unknownJavaStringRepresentation(locationOf(context.getUri(), repStr), repStr.getValue()));
}
// does string rep even make sense here? is type even a string?
if (!AvroType.STRING.equals(avroType)) {
result.recordIssue(AvscIssues.stringRepresentationOnNonString(locationOf(context.getUri(), repStr), repStr.getValue(), avroType));
}
}
return result;
}
use of com.linkedin.avroutil1.parser.jsonpext.JsonObjectExt in project avro-util by linkedin.
the class AvscParser method getOptionalInteger.
private Located<Integer> getOptionalInteger(JsonObjectExt node, String prop, AvscFileParseContext context) {
JsonValueExt val = node.get(prop);
if (val == null) {
return null;
}
JsonValue.ValueType valType = val.getValueType();
if (valType != JsonValue.ValueType.NUMBER) {
context.addIssue(AvscIssues.badPropertyType(prop, locationOf(context.getUri(), val), val, valType.name(), JsonValue.ValueType.NUMBER.name()));
return null;
}
JsonNumberExt numberNode = (JsonNumberExt) val;
if (!numberNode.isIntegral()) {
context.addIssue(AvscIssues.badPropertyType(prop, locationOf(context.getUri(), val), val, "floating point value", "integer"));
return null;
}
return new Located<>(numberNode.intValueExact(), Util.convertLocation(val.getStartLocation()));
}
Aggregations