JSON schema validation broken after 5.9.0

critical

#1

We’re noticing that the ability to do JSON schema validation using using everit’s JSON validator referenced here appears to have broken sometime after 5.9.0.

Error message when running the same script in v6.0.4 on:

org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.NoSuchMethodError: org.json.JSONObject.toMap()Ljava/util/Map;
	at com.api.EveritValidator.invokeMethod(EveritValidator.groovy)
	at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:49)
	at Crud_v3.11 - Retrieve campaign, validate JSON.run(Crud_v3.11 - Retrieve campaign, validate JSON:25)
	at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:342)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:333)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:312)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:304)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:238)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
	at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
	at TempTestCase1555593737838.run(TempTestCase1555593737838.groovy:21)
Caused by: java.lang.NoSuchMethodError: org.json.JSONObject.toMap()Ljava/util/Map;
	at org.everit.json.schema.loader.SchemaLoader$SchemaLoaderBuilder.schemaJson(SchemaLoader.java:187)
	at org.everit.json.schema.loader.SchemaLoader.load(SchemaLoader.java:259)
	at org.everit.json.schema.loader.SchemaLoader.load(SchemaLoader.java:245)
	at org.everit.json.schema.loader.SchemaLoader$load.call(Unknown Source)
	at com.api.EveritValidator.verifyJsonSchema(EveritValidator.groovy:23)
	at com.api.EveritValidator.invokeMethod(EveritValidator.groovy)
	at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:49)
	at Script1540201659864.run(Script1540201659864.groovy:25)
	... 11 more

Test Case:

WS.comment("Validate response schema")
responseJson = response.getResponseBodyContent()
CustomKeywords.'com.api.EveritValidator.verifyJsonSchema'(responseJson, schema)

EveritValidator:

class EveritValidator {

	/**
	 * Send request and verify status code
	 * @param stringJson Json to validate
	 * @param stringSchema validation schema
	 */
	@Keyword
	def verifyJsonSchema(String stringJson, String stringSchema) {
		JSONObject rawSchema = new JSONObject(new JSONTokener(stringSchema))
		Schema schema = SchemaLoader.load(rawSchema)

		try {
			schema.validate(new JSONObject(stringJson))
			KeywordUtil.markPassed("Valid schema")
		} catch (ValidationException e) {
			StringBuffer outmessage = new StringBuffer()
			outmessage << e.getMessage() << "\n"
			e.getAllMessages().each { msg -> outmessage << "$msg \n" }
			KeywordUtil.markFailed(outmessage as String)
		}
	}
}

Please advise. Again, when we run it on 5.9, no problems at all. Any versions later and it fails with the error listed above.

Thanks!


Justify, a JSON Schema Validator, in Katalon Studio
#2

@Ibus maybe you can help us :smiley:.


#3

Hey Morgan

Not sure if this will help, I’m not familiar with this API set.

In the linked discussion, @Ibus makes a point that you should use a JSON array object (and not a JSON object object):


#4

Hi Russ! I tried that when I was troubleshooting but it didn’t seem to make any difference. Thanks though!


#6

In the linked discussion, the response is retuned as an Array and that’s why you need the JSONArray. This API will return a Json Object.
The API response is kinda like this:
{
“Name”: “test”,
“DateCreated”: “2019-04-10T12:36:51”,
“StartDate”: “2019-04-12T21:00:00”,
“EndDate”: “2019-04-13T20:59:00”,
“LastUpdated”: “2019-04-15T12:45:32”
}


#7

@Morgan @Mihai_Augustin_Sarat
i will look into it … i no longer have kata installed but will do it tomorrow if the time allows
most probably with the new version some .jar’s are conflicting …


#8

@Russ_Thomas is a different case now … but that reminds me that i promised to make a coherent tutorial on this matter … will do one day …
perhaps i havr to re-write the keyword to make it aware of the response type and choose array or object … that will save some people from headache :slight_smile:


#9

@Morgan can you please edit your post and re-format the log as /code mark-up to make it more readable? i think the forum plaform is js just using markdown, you have hints in the edit area and preview. pleaaase


#10

I guessed as much.

I edited Morgan’s post for code.


#11

Please do! :smiley:


#12

I did some research, and, as I was afraid the issue is created by the org.json library being added into the Katalon since … I don’t know exactly what version.
E.g, opening a sample project with Katalon 5.9.0 the following is generated into the project .classpath file (stripped content to the lines we are interested):

...........
	<classpathentry kind="lib" path="D:/Katalon Studio/Schema Validation/Drivers/json-20180130.jar"/>
	<classpathentry kind="lib" path="D:/Katalon Studio/Schema Validation/Drivers/org.everit.json.schema-1.9.2.jar"/>
...........

We have only json-20180130.jar grabbed by the everit.json as a dep and the test is running just fine.

However, with 6.1.2 we may find as follows:

...........
<classpathentry kind="lib" path="D:/PRGs/Katalon_Studio_Windows_64-6.1.2/plugins/org.json_20140107.0.0.jar"/>
...........
	<classpathentry kind="lib" path="D:/Katalon Studio/Schema Validation/Drivers/json-20180130.jar"/>
	<classpathentry kind="lib" path="D:/Katalon Studio/Schema Validation/Drivers/org.everit.json.schema-1.9.2.jar"/>
...........

Note that, in addition to the org.json lib we import into the project, we have also org.json_20140107.0.0.jar, the one used by katalon himself, which is an older version.
Unfortunately, Katalon is attempting to load that one … and not the one we need, therefore the error above.

So … we may have to summon other jedi master’s to help us in solving it.
@devalex88 @kazurayam any idea how can we convince katalon to compile/import at the TestCase runtime the right library from the project and not the one from Kata … and only for the keyword/testcase? Attemtping to replace the library in Katalon himself lead to crash, looking into logs looks like plenty of katalon libs depend on that one …


Justify, a JSON Schema Validator, in Katalon Studio
#13

I’ve marked this as critical. We will work on this next week.


#14

#15

@Ibus thanks for looking into it :smile: You deserve a nice cold beer. Maybe next time :smile:


#16

Wow - thanks for looking into this @Ibus! Beers on @Mihai_Augustin_Sarat! :grin:


#17

@Morgan @Mihai_Augustin_Sarat
let’s wait the issue solved to be.
strong is the force of dark in java, the path of deps hidden may be, young padawans …


#18

Hey @devalex88,
Any news on when this is going to be fixed ?
Thanks.


#19

@Mihai_Augustin_Sarat you can try to use jackson untill this get fixed … altough i don’t remember what are the deps of it …

from various logs posted here and there,i think jackson is already present in katalon. you will have to write a new keyword … but you can figure it out. i think it is still one wroted by me in one of the poc projects …

see: https://github.com/java-json-tools/json-schema-validator

use the code samples to figure out how it works:
http://java-json-tools.github.io/json-schema-validator/2.2.x/index.html?com/github/fge/jsonschema/examples/package-summary.html


#20

An alternative is here: Justify


#21

@kazurayam nice.
more options, better flexibility.