Search in sources :

Example 6 with Located

use of com.linkedin.avroutil1.parser.Located 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()));
}
Also used : Located(com.linkedin.avroutil1.parser.Located) JsonValue(jakarta.json.JsonValue) JsonValueExt(com.linkedin.avroutil1.parser.jsonpext.JsonValueExt) JsonNumberExt(com.linkedin.avroutil1.parser.jsonpext.JsonNumberExt)

Example 7 with Located

use of com.linkedin.avroutil1.parser.Located 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

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