use of com.linkedin.avroutil1.model.SchemaOrRef 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.model.SchemaOrRef in project avro-util by linkedin.
the class AvscParser method parse.
private AvscParseResult parse(AvscFileParseContext context, Reader reader) {
JsonReaderExt jsonReader = new JsonReaderWithLocations(reader, null);
JsonValueExt root;
AvscParseResult result = new AvscParseResult();
try {
root = jsonReader.readValue();
} 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 {
SchemaOrRef schemaOrRef = parseSchemaDeclOrRef(root, context, true);
context.resolveReferences();
result.recordParseComplete(context);
} catch (Exception parseIssue) {
result.recordError(parseIssue);
}
return result;
}
use of com.linkedin.avroutil1.model.SchemaOrRef in project avro-util by linkedin.
the class AvscParser method parseUnionSchema.
private SchemaOrRef parseUnionSchema(JsonArrayExt arrayNode, AvscFileParseContext context, boolean topLevel) {
CodeLocation codeLocation = locationOf(context.getUri(), arrayNode);
List<SchemaOrRef> unionTypes = new ArrayList<>(arrayNode.size());
for (JsonValue jsonValue : arrayNode) {
JsonValueExt unionNode = (JsonValueExt) jsonValue;
SchemaOrRef type = parseSchemaDeclOrRef(unionNode, context, false);
unionTypes.add(type);
}
AvroUnionSchema unionSchema = new AvroUnionSchema(codeLocation);
unionSchema.setTypes(unionTypes);
context.defineSchema(unionSchema, topLevel);
return new SchemaOrRef(codeLocation, unionSchema);
}
Aggregations