Saturday 15 February 2014

How to load JSON Schema file from java -



How to load JSON Schema file from java -

my project maven project , within resources folder - src/main/resources folder have json schema file - "jsonschema.json "

package : src/main/resources file : jsonschema.json

now want validate jsonobject json schema

how load schema.json file in code :

is below line correct.

jsonnode schema = jsonloader.fromresource("/jsonschema.json"); // correct? or right me jsonnode info = jsonloader.fromstring(jsondata); processingreport study = validator.validate(schema, data);

this may help place jsonschema file on project root directory or in resource , read schema using normal file read , store in variable str

booleab isvalidrequest=false; string requestdata; // info validate string str; //schema jsonnode requestdatajsonnode = com.github.fge.jackson.jsonloader.fromstring(requestdata); final jsonnode schemanode = jsonloader.fromstring(str); // final jsonnode schemanode=jsonloader.fromresource("jsonschema.json"); query // final jsonschemafactory mill = jsonschemafactory.bydefault(); jsonvalidator validator = factory.getvalidator(); processingreport processingreport= validator.validate(schemanode, requestdatajsonnode); if(processingreport!=null) { isvalidrequest=processingreport.issuccess(); } } grab (exception e) { }

if getting exception while executing program. add together dependencies listed in below [link]

http://mvnrepository.com/artifact/com.github.fge/json-schema-validator/2.2.5

java json jsonschema json-schema-validator

No comments:

Post a Comment