Search in sources :

Example 1 with JsonParseException

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

the class AvscParser method parse.

public AvscParseResult parse(String avsc) {
    JsonReaderExt jsonReader = new JsonReaderWithLocations(new StringReader(avsc), null);
    JsonObjectExt root;
    AvscFileParseContext context = new AvscFileParseContext(avsc);
    AvscParseResult result = new AvscParseResult();
    try {
        root = jsonReader.readObject();
    } 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 {
        parseSchemaDeclOrRef(root, context, true);
        context.resolveReferences();
        result.recordParseComplete(context);
    } catch (Exception parseIssue) {
        result.recordError(parseIssue);
    }
    return result;
}
Also used : JsonObjectExt(com.linkedin.avroutil1.parser.jsonpext.JsonObjectExt) JsonReaderWithLocations(com.linkedin.avroutil1.parser.jsonpext.JsonReaderWithLocations) StringReader(java.io.StringReader) JsonReaderExt(com.linkedin.avroutil1.parser.jsonpext.JsonReaderExt) JsonParseException(com.linkedin.avroutil1.parser.exceptions.JsonParseException) ParseException(com.linkedin.avroutil1.parser.exceptions.ParseException) JsonParsingException(jakarta.json.stream.JsonParsingException) AvroSyntaxException(com.linkedin.avroutil1.parser.exceptions.AvroSyntaxException) JsonParseException(com.linkedin.avroutil1.parser.exceptions.JsonParseException) JsonParsingException(jakarta.json.stream.JsonParsingException)

Aggregations

AvroSyntaxException (com.linkedin.avroutil1.parser.exceptions.AvroSyntaxException)1 JsonParseException (com.linkedin.avroutil1.parser.exceptions.JsonParseException)1 ParseException (com.linkedin.avroutil1.parser.exceptions.ParseException)1 JsonObjectExt (com.linkedin.avroutil1.parser.jsonpext.JsonObjectExt)1 JsonReaderExt (com.linkedin.avroutil1.parser.jsonpext.JsonReaderExt)1 JsonReaderWithLocations (com.linkedin.avroutil1.parser.jsonpext.JsonReaderWithLocations)1 JsonParsingException (jakarta.json.stream.JsonParsingException)1 StringReader (java.io.StringReader)1