networknt / json-schema-validator

A fast Java JSON schema validator that supports draft V4, V6, V7, V2019-09 and V2020-12
Apache License 2.0
858 stars 325 forks source link

Unexpected character ('<' (code 60)) #42

Closed dbeja closed 5 years ago

dbeja commented 7 years ago

Hi,

I'm trying to use your lib to validate some json using this schema: https://realtime-listings.webservices.zpg.co.uk/docs/latest/schemas/listing/update.json

But I always get this error when loading schema file:

com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
 at [Source: sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@2d7a42eb; line: 1, column: 2]
    at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1702) ~[jackson-core-2.8.4.jar:2.8.4]
    at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:558) ~[jackson-core-2.8.4.jar:2.8.4]
    at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:456) ~[jackson-core-2.8.4.jar:2.8.4]
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._handleUnexpectedValue(UTF8StreamJsonParser.java:2689) ~[jackson-core-2.8.4.jar:2.8.4]
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._nextTokenNotInObject(UTF8StreamJsonParser.java:878) ~[jackson-core-2.8.4.jar:2.8.4]
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:772) ~[jackson-core-2.8.4.jar:2.8.4]
    at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:3834) ~[jackson-databind-2.8.4.jar:2.8.4]
    at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3783) ~[jackson-databind-2.8.4.jar:2.8.4]
    at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:2321) ~[jackson-databind-2.8.4.jar:2.8.4]
    at com.networknt.schema.JsonSchemaFactory.getSchema(JsonSchemaFactory.java:63) [json-schema-validator-0.1.7.jar:na]
    at com.networknt.schema.BaseJsonValidator.obainSubSchemaNode(BaseJsonValidator.java:72) [json-schema-validator-0.1.7.jar:na]
    at com.networknt.schema.BaseJsonValidator.<init>(BaseJsonValidator.java:41) [json-schema-validator-0.1.7.jar:na]
    at com.networknt.schema.JsonSchema.<init>(JsonSchema.java:49) [json-schema-validator-0.1.7.jar:na]
    at com.networknt.schema.JsonSchema.<init>(JsonSchema.java:44) [json-schema-validator-0.1.7.jar:na]
    at com.networknt.schema.JsonSchemaFactory.getSchema(JsonSchemaFactory.java:44) [json-schema-validator-0.1.7.jar:na]

I even tried to sout the schema json content and looks ok.

I also tried to use https://json-schema-validator.herokuapp.com/index.jsp and the schema validates alright on Schema Syntax Validation but I get the same error if I try to use it on Instance Validation.

Any clues what's wrong with this schema file?

Thanks!

stevehu commented 7 years ago

@dbeja You schema looks good. I guess the json data is the problem and I am wonder if you could verify you data with the following online validators.

http://www.jsonschemavalidator.net/ https://json-schema-validator.herokuapp.com/

Thanks.

djarnis73 commented 6 years ago

Since the schema itself does not contain any '<' characters and the stacktrace comes from a HttpURLConnection there is a good chance that the connections somehow failed and returned html instead of json. Perhaps there is a proxy server or firewall in the equation.

I suggest that you download the schema to a local file and load that instead.