Search in sources :

Example 6 with AvroSyntaxException

use of com.linkedin.avroutil1.parser.exceptions.AvroSyntaxException in project avro-util by linkedin.

the class AvscParser method getOptionalString.

private Located<String> getOptionalString(JsonObjectExt node, String prop) {
    JsonValueExt val = node.get(prop);
    if (val == null) {
        return null;
    }
    JsonValue.ValueType valType = val.getValueType();
    if (valType != JsonValue.ValueType.STRING) {
        throw new AvroSyntaxException("\"" + prop + "\" property at " + val.getStartLocation() + " is expected to be a string, not a " + JsonPUtil.describe(valType) + " (" + val + ")");
    }
    return new Located<>(((JsonStringExt) val).getString(), Util.convertLocation(val.getStartLocation()));
}
Also used : AvroSyntaxException(com.linkedin.avroutil1.parser.exceptions.AvroSyntaxException) Located(com.linkedin.avroutil1.parser.Located) JsonValue(jakarta.json.JsonValue) JsonValueExt(com.linkedin.avroutil1.parser.jsonpext.JsonValueExt)

Aggregations

AvroSyntaxException (com.linkedin.avroutil1.parser.exceptions.AvroSyntaxException)6 JsonValueExt (com.linkedin.avroutil1.parser.jsonpext.JsonValueExt)4 CodeLocation (com.linkedin.avroutil1.model.CodeLocation)3 SchemaOrRef (com.linkedin.avroutil1.model.SchemaOrRef)3 JsonValue (jakarta.json.JsonValue)3 AvroNamedSchema (com.linkedin.avroutil1.model.AvroNamedSchema)2 AvroSchema (com.linkedin.avroutil1.model.AvroSchema)2 AvroType (com.linkedin.avroutil1.model.AvroType)2 JsonPropertiesContainer (com.linkedin.avroutil1.model.JsonPropertiesContainer)2 JsonArrayExt (com.linkedin.avroutil1.parser.jsonpext.JsonArrayExt)2 AvroEnumSchema (com.linkedin.avroutil1.model.AvroEnumSchema)1 AvroFixedSchema (com.linkedin.avroutil1.model.AvroFixedSchema)1 AvroLiteral (com.linkedin.avroutil1.model.AvroLiteral)1 AvroLogicalType (com.linkedin.avroutil1.model.AvroLogicalType)1 AvroRecordSchema (com.linkedin.avroutil1.model.AvroRecordSchema)1 AvroSchemaField (com.linkedin.avroutil1.model.AvroSchemaField)1 TextLocation (com.linkedin.avroutil1.model.TextLocation)1 Located (com.linkedin.avroutil1.parser.Located)1 JsonNumberExt (com.linkedin.avroutil1.parser.jsonpext.JsonNumberExt)1 JsonObjectExt (com.linkedin.avroutil1.parser.jsonpext.JsonObjectExt)1