java - No class found Exception while validating Json with JsonSchema -


i new java.

i trying validate json jsonschema. have referred java/android - validate string json against string schema.. have tried #tihamer code , getting jsonparserexception have not used it.

below code

import java.util.iterator; import com.fasterxml.jackson.databind.jsonnode; import com.github.fge.jackson.jsonloader; import com.github.fge.jsonschema.core.report.processingmessage; import com.github.fge.jsonschema.core.report.processingreport; import com.github.fge.jsonschema.main.jsonschema; import com.github.fge.jsonschema.main.jsonschemafactory;  public class jsonvalidation {     public static void main(string[] args)     {         jsonvalidation jv = new jsonvalidation();         string jsondata = "{\"dispatchermode\":\"standard\",\"noofdispatcher\":\"3\",\"dispatcherinfo\":[{\"dispatcher\":\"dispatcher 0 = 156.95.53.243:6108<--current\"},{\"dispatcher\":\"dispatcher 1 = 156.95.53.220:6108\"},{\"dispatcher\":\"dispatcher 2 = 172.26.41.113:6108\"}],\"noofauthserver\":\"3\",\"connected\":\"3\",\"authorizationinfo\":[{\"authserver\":\"authserver 0 = 172.26.41.114:6115(connected)<--current\",\"requests\":\"1503\",\"failures\":\"1\",\"queued\":\"0\",\"delay\":\"10225\"},{\"authserver\":\"authserver 1 = 156.95.53.220:6115(connected)\",\"requests\":\"10745\",\"failures\":\"0\",\"queued\":\"0\",\"delay\":\"5762\"},{\"authserver\":\"authserver 2 = 172.26.41.113:6115(connected)\",\"requests\":\"12545\",\"failures\":\"1\",\"queued\":\"0\",\"delay\":\"9756\"}],\"noofcache\":\"2\",\"cacheinfo\":[{\"cachenumber\":\"cache 0\",\"request\":\"0\",\"hits\":\"0\",\"entries\":\"0\",\"size\":\"10000\",\"ttl\":\"600sec\"},{\"cachenumber\":\"cache 1\",\"request\":\"1\",\"hits\":\"1\",\"entries\":\"1\",\"size\":\"12000\",\"ttl\":\"300sec\"}]}";         string jsonschema = "{\"type\": \"object\",\"properties\": {\"dispatchermode\": {\"type\": \"string\"},\"noofdispatcher\": {\"type\": \"string\"},\"dispatcherinfo\": {\"type\": \"array\",\"items\": [{\"type\": \"object\",\"properties\": {\"dispatcher\": {\"type\": \"string\"}}},{\"type\": \"object\",\"properties\": {\"dispatcher\": {\"type\": \"string\"}}},{\"type\": \"object\",\"properties\": {\"dispatcher\": {\"type\": \"string\"}}}]},\"noofauthserver\": {\"type\": \"string\"},\"connected\": {\"type\": \"string\"},\"authorizationinfo\": {\"type\": \"array\",\"items\": [{\"type\": \"object\",\"properties\": {\"authserver\": {\"type\": \"string\"},\"requests\": {\"type\": \"string\"},\"failures\": {\"type\": \"string\"},\"queued\": {\"type\": \"string\"},\"delay\": {\"type\": \"string\"}}},{\"type\": \"object\",\"properties\": {\"authserver\": {\"type\": \"string\"},\"requests\": {\"type\": \"string\"},\"failures\": {\"type\": \"string\"},\"queued\": {\"type\": \"string\"},\"delay\": {\"type\": \"string\"}}},{\"type\": \"object\",\"properties\": {\"authserver\": {\"type\": \"string\"},\"requests\": {\"type\": \"string\"},\"failures\": {\"type\": \"string\"},\"queued\": {\"type\": \"string\"},\"delay\": {\"type\": \"string\"}}}]},\"noofcache\": {\"type\": \"string\"},\"cacheinfo\": {\"type\": \"array\",\"items\": [{\"type\": \"object\",\"properties\": {\"cachenumber\": {\"type\": \"string\"},\"request\": {\"type\": \"string\"},\"hits\": {\"type\": \"string\"},\"entries\": {\"type\": \"string\"},\"size\": {\"type\": \"string\"},\"ttl\": {\"type\": \"string\"}}},{\"type\": \"object\",\"properties\": {\"cachenumber\": {\"type\": \"string\"},\"request\": {\"type\": \"string\"},\"hits\": {\"type\": \"string\"},\"entries\": {\"type\": \"string\"},\"size\": {\"type\": \"string\"},\"ttl\": {\"type\": \"string\"}}}]}},\"required\": [\"dispatchermode\",\"noofdispatcher\",\"dispatcherinfo\",\"noofauthserver\",\"connected\",\"authorizationinfo\",\"noofcache\",\"cacheinfo\"]}";         jv.validation(jsondata, jsonschema);     }       public boolean validation(string  jsondata, string jsonschema)     {         processingreport report = null;         boolean result = false;         try{             jsonnode schemanode = jsonloader.fromstring(jsonschema);             jsonnode datanode = jsonloader.fromstring(jsondata);             jsonschemafactory factory = jsonschemafactory.bydefault();             jsonschema schema = factory.getjsonschema(schemanode);             report = schema.validate(datanode);         }         catch(exception ex){             ex.printstacktrace();         }           if (report != null) {             iterator<processingmessage> iter = report.iterator();             while (iter.hasnext()) {                 processingmessage pm = iter.next();                 system.out.println("processing message: "+pm.getmessage());             }             result = report.issuccess();         }         system.out.println(" result=" +result);         return result;     }  } 

and below error

exception in thread "main" java.lang.noclassdeffounderror: com/fasterxml/jackson/core/jsonparseexception     @ com.github.fge.jackson.jsonloader.<clinit>(jsonloader.java:50)     @ jsonvalidation.validation(jsonvalidation.java:25)     @ jsonvalidation.main(jsonvalidation.java:16) caused by: java.lang.classnotfoundexception: com.fasterxml.jackson.core.jsonparseexception     @ java.net.urlclassloader$1.run(unknown source)     @ java.net.urlclassloader$1.run(unknown source)     @ java.security.accesscontroller.doprivileged(native method)     @ java.net.urlclassloader.findclass(unknown source)     @ java.lang.classloader.loadclass(unknown source)     @ sun.misc.launcher$appclassloader.loadclass(unknown source)     @ java.lang.classloader.loadclass(unknown source)     ... 3 more 

i solved previous error getting error

exception in thread "main" java.lang.nosuchmethoderror: com.fasterxml.jackson.core.jsonfactory.requirespropertyordering()z     @ com.fasterxml.jackson.databind.objectmapper.<init>(objectmapper.java:537)     @ com.fasterxml.jackson.databind.objectmapper.<init>(objectmapper.java:448)     @ com.github.fge.jackson.jacksonutils.newmapper(jacksonutils.java:155)     @ com.github.fge.jackson.jacksonutils.<clinit>(jacksonutils.java:55)     @ com.github.fge.jackson.jsonnodereader.<init>(jsonnodereader.java:82)     @ com.github.fge.jackson.jsonloader.<clinit>(jsonloader.java:50)     @ com.github.fge.jsonschema.examples.utils.loadresource(utils.java:53)     @ jsonvalidatetest.main(jsonvalidatetest.java:19) 

i have not used objectmapper class getting exception.

see following part in stack trace:

caused by: java.lang.classnotfoundexception: com.fasterxml.jackson.core.jsonparseexception     @ java.net.urlclassloader$1.run(unknown source)     ... 

it suggests error caused class jsonparseexception of package com.fasterxml.jackson.core jvm tried load not find not in classpath.

just add com.fasterxml.jackson.core jar file in classpath.


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -