Hi,
I'm using to Wiremock to mock my response.
My Json Schema and Json body is as below:
Json Schema:
{
"$schema": "
http://json-schema.org/draft-04/schema#",
"title": "Product set",
"items": {
"title": "product",
"type": "object",
"properties": {
"productId": {
"type": "number"
},
"productName": {
"type": "string"
},
"productPrice": {
"type": "number",
"minimum": 0
},
"dimensions": {
"type": "object",
"properties": {
"length": {"type": "number"},
"width": {"type": "number"},
"height": {"type": "number"}
}
}
},
"required": ["productId", "productName"]
}
}
Json Body:
"product":{
"productId":"5",
"productName":"Television",
"productPrice":1200,
"dimensions":[{
"length":35,
"width":50,
"height":45
}]
}
}
I have validated the Json body with schema with an online available validator and body conforms to schema.
I'm using below code to send the response and Json schema as string, where content contains the schema.
assertThat(response.toString(), matchesJsonSchema((content)));
But while I try to assert against schema i get the below error:
io.restassured.module.jsv.JsonSchemaValidationException: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'com': was expecting ('true', 'false' or 'null')
at [Source: java.io.StringReader@b9267b; line: 1, column: 4]
at io.restassured.module.jsv.JsonSchemaValidator.matchesSafely(JsonSchemaValidator.java:233)
at io.restassured.module.jsv.JsonSchemaValidator.matchesSafely(JsonSchemaValidator.java:75)
at org.hamcrest.TypeSafeMatcher.matches(TypeSafeMatcher.java:65)
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:12)
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:8)
at TestRestAssured.RestAssuredHamcrest.validateSchema(RestAssuredHamcrest.java:68)
at TestRestAssured.RestAssuredHamcrest.main(RestAssuredHamcrest.java:57)
Caused by: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'com': was expecting ('true', 'false' or 'null')
at [Source: java.io.StringReader@b9267b; line: 1, column: 4]
at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1586)
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:521)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._reportInvalidToken(ReaderBasedJsonParser.java:2754)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._handleOddValue(ReaderBasedJsonParser.java:1820)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:708)
at com.fasterxml.jackson.databind.MappingIterator.hasNextValue(MappingIterator.java:240)
at com.github.fge.jackson.JsonNodeReader.readNode(JsonNodeReader.java:142)
at com.github.fge.jackson.JsonNodeReader.fromReader(JsonNodeReader.java:127)
at com.github.fge.jackson.JsonLoader.fromReader(JsonLoader.java:179)
at com.github.fge.jackson.JsonLoader.fromString(JsonLoader.java:192)
at io.restassured.module.jsv.JsonSchemaValidator.matchesSafely(JsonSchemaValidator.java:214)
... 6 more
Kindly advise.
Thanks for your help in advance.
Regards,
Cema