use of com.linkedin.avroutil1.compatibility.SchemaValidator in project avro-util by linkedin.
the class Avro15Adapter method parse.
@Override
public SchemaParseResult parse(String schemaJson, SchemaParseConfiguration desiredConf, Collection<Schema> known) {
Schema.Parser parser = new Schema.Parser();
boolean validateNames = true;
boolean validateDefaults = false;
if (desiredConf != null) {
validateNames = desiredConf.validateNames();
validateDefaults = desiredConf.validateDefaultValues();
}
SchemaParseConfiguration configUsed = new SchemaParseConfiguration(validateNames, validateDefaults);
parser.setValidate(validateNames);
if (known != null && !known.isEmpty()) {
Map<String, Schema> knownByFullName = new HashMap<>(known.size());
for (Schema s : known) {
knownByFullName.put(s.getFullName(), s);
}
parser.addTypes(knownByFullName);
}
Schema mainSchema = parser.parse(schemaJson);
if (validateDefaults) {
// avro 1.5 doesnt properly validate default values, so we have to do it ourselves
SchemaValidator validator = new SchemaValidator(configUsed, known);
// will throw on issues
AvroSchemaUtil.traverseSchema(mainSchema, validator);
}
Map<String, Schema> knownByFullName = parser.getTypes();
return new SchemaParseResult(mainSchema, knownByFullName, configUsed);
}
use of com.linkedin.avroutil1.compatibility.SchemaValidator in project avro-util by linkedin.
the class Avro16Adapter method parse.
@Override
public SchemaParseResult parse(String schemaJson, SchemaParseConfiguration desiredConf, Collection<Schema> known) {
Schema.Parser parser = new Schema.Parser();
boolean validateNames = true;
boolean validateDefaults = false;
if (desiredConf != null) {
validateNames = desiredConf.validateNames();
validateDefaults = desiredConf.validateDefaultValues();
}
SchemaParseConfiguration configUsed = new SchemaParseConfiguration(validateNames, validateDefaults);
parser.setValidate(validateNames);
if (known != null && !known.isEmpty()) {
Map<String, Schema> knownByFullName = new HashMap<>(known.size());
for (Schema s : known) {
knownByFullName.put(s.getFullName(), s);
}
parser.addTypes(knownByFullName);
}
Schema mainSchema = parser.parse(schemaJson);
if (validateDefaults) {
// avro 1.6 doesnt properly validate default values, so we have to do it ourselves
SchemaValidator validator = new SchemaValidator(configUsed, known);
// will throw on issues
AvroSchemaUtil.traverseSchema(mainSchema, validator);
}
Map<String, Schema> knownByFullName = parser.getTypes();
return new SchemaParseResult(mainSchema, knownByFullName, configUsed);
}
use of com.linkedin.avroutil1.compatibility.SchemaValidator in project avro-util by linkedin.
the class Avro17Adapter method parse.
@Override
public SchemaParseResult parse(String schemaJson, SchemaParseConfiguration desiredConf, Collection<Schema> known) {
Schema.Parser parser = new Schema.Parser();
boolean validateNames = true;
boolean validateDefaults = true;
if (desiredConf != null) {
validateNames = desiredConf.validateNames();
validateDefaults = desiredConf.validateDefaultValues();
}
SchemaParseConfiguration configUsed = new SchemaParseConfiguration(validateNames, validateDefaults);
parser.setValidate(validateNames);
// must check the method exists before trying to call it
if (setValidateDefaultsMethod != null) {
parser.setValidateDefaults(validateDefaults);
}
if (known != null && !known.isEmpty()) {
Map<String, Schema> knownByFullName = new HashMap<>(known.size());
for (Schema s : known) {
knownByFullName.put(s.getFullName(), s);
}
parser.addTypes(knownByFullName);
}
Schema mainSchema = parser.parse(schemaJson);
if (validateDefaults && setValidateDefaultsMethod == null) {
// older avro 1.7 doesnt support validating default values, so we have to do it ourselves
SchemaValidator validator = new SchemaValidator(configUsed, known);
// will throw on issues
AvroSchemaUtil.traverseSchema(mainSchema, validator);
}
Map<String, Schema> knownByFullName = parser.getTypes();
return new SchemaParseResult(mainSchema, knownByFullName, configUsed);
}
use of com.linkedin.avroutil1.compatibility.SchemaValidator in project avro-util by linkedin.
the class Avro14Adapter method parse.
@Override
public SchemaParseResult parse(String schemaJson, SchemaParseConfiguration desiredConf, Collection<Schema> known) {
SchemaParseResult result = Avro14SchemaAccessUtil.parse(schemaJson, known);
if (desiredConf != null && !desiredConf.equals(result.getConfigUsed())) {
// avro 1.4 doesnt validate anything, so if user wants anything stricter we have to do it ourselves
Schema schema = result.getMainSchema();
SchemaValidator validator = new SchemaValidator(desiredConf, known);
// will throw on issues
AvroSchemaUtil.traverseSchema(schema, validator);
return new SchemaParseResult(result.getMainSchema(), result.getAllSchemas(), desiredConf);
} else {
return result;
}
}
Aggregations