EzDevInfo.com

json-schema-validator

A JSON Schema validation implementation in pure Java, which aims for correctness and performance, in that order JSON Schema validation online validate your json data against a json schema

JSON schema: date greater than an other

I've a json schema like this:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "Operation",
  "description": "The schema of an operation",
  "type": "object",
  "properties": {
    "id":{
      "description": "Unique identifier of the service",
      "type": "string"
    },
    "description":{
      "type": "string"
    },
    "dateDebut":{
      "type": "string",
      "format": "date-time"
    },
    "dateFin":{
      "type": "string",
      "format": "date-time"
    }
  }
}

How can I say in my schema that the dateFin must be greater than the dateDebut ?


Source: (StackOverflow)

Referencing a local relative file in a JSON Schema?

I am building a JSON for a REST web service. The schema however has grown to over 1300 lines and I want to split it up across multiple files. I am unit testing my schema against a folder of JSON sample responses using json-schema-validator version 2.1.8.

I know you have import types defined in your current file like { "$ref": "#/definitions/MyBool" }, however if I wanted to move the definition of MyBool to another file, like Common.schema.json, how would I reference it then?

I tried { "$ref": "Common.schema.json/definitions/MyBoolean" }, { "$ref": "./Common.schema.json/defintion/MyBoolean" }, and { "$ref": "file://./Common.schema.json/definitions/MyBoolean" } but none of them work.

The answer on "Does JSON Schema validation in common-js utils support references?" seems like it should work but I can't seem to get the syntax right.

I'm loading the schema with:

JsonNode mySchema = JsonLoader.fromReader(   new InputStreamReader(  JsonSchemaTest.class.getResourceAsStream( "/json/schema/MySchema.schema.json" )  )   );

and then validating it with:

JsonSchemaFactory.byDefault().getValidator().validate(   schema,   new InputStreamReader(  getClass().getResourceAsStream( "/json/sample/MyJsonSample.json" )  )   ).isSuccess();

FWIW MyBool looks like:

"MyBool": {
    "type": "object",
    "properties": {
        "value" :{
            "type": "string",
            "enum": [ "true", "false", "file not found" ]
        }
    },
    "required": ["value"],
    "additionalProperties": false
}

When I don't try to extract MyBool, the schema validates all my JSON samples correctly.


The exception I receive is:

com.github.fge.jsonschema.core.exceptions.ProcessingException: fatal: unable to dereference URI "file:/Common.schema.json/definitions/MyBool#"
    level: "fatal"
    uri: "file:/Common.schema.json/definitions/MyBool#"
    exceptionMessage: "\\Common.schema.json\\definitions\\MyBool (The system cannot find the path specified)"

    at com.github.fge.jsonschema.core.load.URIManager.getContent(URIManager.java:108)
    at com.github.fge.jsonschema.core.load.SchemaLoader$1.load(SchemaLoader.java:108)
    at com.github.fge.jsonschema.core.load.SchemaLoader$1.load(SchemaLoader.java:103)
    at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3524)
    at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2317)
    at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2280)
    at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2195)
    at com.google.common.cache.LocalCache.get(LocalCache.java:3934)
    at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3938)
    at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4821)
    at com.github.fge.jsonschema.core.load.SchemaLoader.get(SchemaLoader.java:165)
    at com.github.fge.jsonschema.core.load.RefResolver.rawProcess(RefResolver.java:113)
    at com.github.fge.jsonschema.core.load.RefResolver.rawProcess(RefResolver.java:50)
    at com.github.fge.jsonschema.core.processing.RawProcessor.process(RawProcessor.java:76)
    at com.github.fge.jsonschema.core.processing.RawProcessor.process(RawProcessor.java:40)
    at com.github.fge.jsonschema.core.processing.ProcessorChain$ProcessorMerger.process(ProcessorChain.java:188)
    at com.github.fge.jsonschema.core.processing.ProcessingResult.of(ProcessingResult.java:78)
    at com.github.fge.jsonschema.core.processing.CachingProcessor$1.load(CachingProcessor.java:127)
    at com.github.fge.jsonschema.core.processing.CachingProcessor$1.load(CachingProcessor.java:119)
    at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3524)
    at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2317)
    at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2280)
    at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2195)
    at com.google.common.cache.LocalCache.get(LocalCache.java:3934)
    at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3938)
    at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4821)
    at com.github.fge.jsonschema.core.processing.CachingProcessor.process(CachingProcessor.java:108)
    at com.github.fge.jsonschema.processors.validation.ValidationChain.process(ValidationChain.java:106)
    at com.github.fge.jsonschema.processors.validation.ValidationChain.process(ValidationChain.java:55)
    at com.github.fge.jsonschema.core.processing.ProcessorMap$Mapper.process(ProcessorMap.java:165)
    at com.github.fge.jsonschema.core.processing.ProcessingResult.of(ProcessingResult.java:78)
    at com.github.fge.jsonschema.core.processing.CachingProcessor$1.load(CachingProcessor.java:127)
    at com.github.fge.jsonschema.core.processing.CachingProcessor$1.load(CachingProcessor.java:119)
    at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3524)
    at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2317)
    at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2280)
    at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2195)
    at com.google.common.cache.LocalCache.get(LocalCache.java:3934)
    at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3938)
    at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4821)
    at com.github.fge.jsonschema.core.processing.CachingProcessor.process(CachingProcessor.java:108)
    at com.github.fge.jsonschema.processors.validation.ValidationProcessor.process(ValidationProcessor.java:83)
    at com.github.fge.jsonschema.processors.validation.ValidationProcessor.processObject(ValidationProcessor.java:179)
    at com.github.fge.jsonschema.processors.validation.ValidationProcessor.process(ValidationProcessor.java:121)
    at com.github.fge.jsonschema.processors.validation.ValidationProcessor.processArray(ValidationProcessor.java:149)
    at com.github.fge.jsonschema.processors.validation.ValidationProcessor.process(ValidationProcessor.java:119)
    at com.github.fge.jsonschema.processors.validation.ValidationProcessor.processObject(ValidationProcessor.java:179)
    at com.github.fge.jsonschema.processors.validation.ValidationProcessor.process(ValidationProcessor.java:121)
    at com.github.fge.jsonschema.processors.validation.ValidationProcessor.process(ValidationProcessor.java:48)
    at com.github.fge.jsonschema.keyword.validator.draftv4.OneOfValidator.validate(OneOfValidator.java:67)
    at com.github.fge.jsonschema.processors.validation.ValidationProcessor.process(ValidationProcessor.java:100)
    at com.github.fge.jsonschema.processors.validation.ValidationProcessor.process(ValidationProcessor.java:48)
    at com.github.fge.jsonschema.core.processing.ProcessingResult.of(ProcessingResult.java:78)
    at com.github.fge.jsonschema.main.JsonValidator.validate(JsonValidator.java:103)
    at com.github.fge.jsonschema.main.JsonValidator.validate(JsonValidator.java:123)
    at com.initech.ws.json.BaseJsonSchemaTest.jsonFileShouldValidate(BaseJsonSchemaTest.java:84)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.junit.runners.Suite.runChild(Suite.java:127)
    at org.junit.runners.Suite.runChild(Suite.java:26)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.junit.runners.Suite.runChild(Suite.java:127)
    at org.junit.runners.Suite.runChild(Suite.java:26)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

Source: (StackOverflow)

Advertisements

Json Schema Data Set for validation testing

I have been looking for a good sample data set of json schemas and corresponding valid and invalid json instances.

I have only found a few test sets in some github projects:

https://github.com/xeipuuv/gojsonschema/tree/master/json_schema_test_suite

https://github.com/fge/json-schema-validator

However the data sets are pretty simple and do not cover all cases.

Does anyone know any good repository with this kind of data set?


Source: (StackOverflow)

Validate Json Schema Draft V4

I have a Json schema as below , when i validate it on a online validatior like http://jsonschemalint.com/draft4/# it says its valid.I changed "type" to "object" , "array" , "string" and kept the rest of the structure same .still it says valid schema. My understanding was when type=object there should be "properties" when type=array there should be"items"

{
  "title": "Example Schema",
  "type": "string",
  "properties": {
    "firstName": {
      "type": "string"
    },
    "lastName": {
      "type": "string"
    }
  },
  "required": [
    "firstName",
    "lastName"
  ]
}

Source: (StackOverflow)

How does jsonschema map the raw json string value to python objects?

How does jsonschema work?

My assumption is that they convert the raw json strings they see into the python type that is listed in say jsonschema.Draft4Validator.DEFAULT_TYPES and see if it can be converted. If the convert is successful, then validation proceeds.

If that's the case, each of the types in python in DEFAULT_TYPES must have a "from string" method that converts a string to that type.

Is my understanding of jsonschema correct?


Source: (StackOverflow)

REST Assured with JSON schema validation not working

I'm working with Spring Boot and REST Assured to test REST APIs. I was trying the example with JSON schema validation but it throws this error:

java.lang.IllegalArgumentException: Schema to use cannot be null

According to documentation, the schema should be located in the classpath. My example schema is located there. Here is my project structure and example schema location:

project structure

Here is my code. Without schema validation it works fine.

given().
    contentType("application/json").
when().
    get("http://myExample/users").
then().
    assertThat().body(matchesJsonSchemaInClasspath("example_schema.json"));

Source: (StackOverflow)

Validating JSON input with a JSON schema

If you specify elements in the input file that is configured as a requirement in the schema, it is validating OK. And if you append the “maxItems”: 1, it does not care if you add another element in the input file, the validator still look at this as a valid input file.

i.e: Schema:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "properties": {
        "Books": {
            "type": "object",
            "minItems": 1,
            "properties": {
                "Book": {
                    "type": "object",
                    "minItems": 1,
                    "maxItems": 1,
                    "properties": {
                        "Author": {
                            "type": "string",
                            "minItems": 1,
                            "maxItems": 1
                        }
                    },
                    "required": ["Author"]
                }
            },
            "required": ["Book"]
        }
    },
    "required": ["Books"]
}

InputFile:

{
    "Books": {
        "Book": {
            "Author": "Andreas",
            "Author": "Geir"
        }
    }
}

Shouldn't this be a invalid inputfile?

The validators:


Source: (StackOverflow)

json-schema-validator NoClassDefFoundError: com/google/common/io/Closer

Solution: Add the guava dependency:

<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>18.0</version>
</dependency>

I'm trying to use the json-schema-validator over here: https://github.com/fge/json-schema-validator .

I'm using the following maven dependency:

<dependency>
    <groupId>com.github.fge</groupId>
    <artifactId>json-schema-validator</artifactId>
    <version>2.2.5</version>
</dependency>

Here is a class I'm trying:

import java.io.IOException;
import com.fasterxml.jackson.databind.JsonNode;
import com.github.fge.jackson.JsonLoader;

public class JsonSchemaTest {
    public static void main(String[] args) throws IOException {
        JsonNode jsonNode = JsonLoader.fromString("{\"a\":1}");
    }
}

And here is the error I'm receiving:

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/io/Closer
    at com.github.fge.jackson.JsonNodeReader.fromReader(JsonNodeReader.java:120)
    at com.github.fge.jackson.JsonLoader.fromReader(JsonLoader.java:179)
    at com.github.fge.jackson.JsonLoader.fromString(JsonLoader.java:192)
    at com.cisco.webex.squared.flume.JsonSchemaTest.main(JsonSchemaTest.java:10)
Caused by: java.lang.ClassNotFoundException: com.google.common.io.Closer
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    ... 4 more

--- Edit:

If I change my maven version to 2.1.7, I can do JsonNode jsonNode = JsonLoader.fromString("{\"a\":1}"); but I cannot create the factory here without the same java.lang.NoClassDefFoundError: com/google/common/io/Closer error:

import com.fasterxml.jackson.databind.JsonNode;
import com.github.fge.jackson.JsonLoader;
import com.github.fge.jsonschema.exceptions.ProcessingException;
import com.github.fge.jsonschema.main.JsonSchema;
import com.github.fge.jsonschema.main.JsonSchemaFactory;
import com.github.fge.jsonschema.report.ProcessingReport;

public final class JsonSchemaTest {
    public static void main(final String[] args) throws IOException, ProcessingException {
         //JsonNode data = JsonLoader.fromString("{\"a\":1}");
        final JsonNode data = JsonLoader.fromString("{\"a\":1}");
        final JsonNode fstabSchema = JsonLoader.fromString("{\"type\":\"object\", \"properties\":{\"a\":{\"type\":\"number\"}}}");

        final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
        final JsonSchema schema = factory.getJsonSchema(fstabSchema);

        ProcessingReport report;

        report = schema.validate(data);
        System.out.println(report);
    }
}

Source: (StackOverflow)

json schema issue on required property

I need to write the JSON Schema based on the specification defined by http://json-schema.org/. But I'm struggling for the required/mandatory property validation. Below is the JSON schema that I have written where all the 3 properties are mandatory but In my case either one should be mandatory. How to do this?.

{
    "id": "http://example.com/searchShops-schema#",
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "searchShops Service",
    "description": "",
    "type": "object",
    "properties": {     
            "city":{
                "type": "string"                
            },  
            "address":{
                "type": "string"                
            },      
            "zipCode":{
                "type": "integer"
            }                   
    },
    "required": ["city", "address", "zipCode"]
}

Source: (StackOverflow)

How to set multiple types for a JsonSchema field in Json.Net?

How can I set Multiple type in a JsonSchema. The description field in the below example I want it to be JsonSchemaType.String or JsonSchemaType.null.

 {PropertyNames.Id, new JsonSchema { Type = JsonSchemaType.Integer, Required = true }},
      {PropertyNames.Description, new JsonSchema { Type = JsonSchemaType.String, Required = true }}

Also, I have an array which consists of Integers and float.

 result[PropertyNames.Metrics] = new JsonSchema { Type = JsonSchemaType.Array, Required = true, Items = new List<JsonSchema> { new JsonSchema() { Type = JsonSchemaType.Integer } } };

The validation fails as it expects integer but receives float. Can I do something like Type = JsonSchemaType.Integer "or" JsonSchemaType.Float


Source: (StackOverflow)

Spring Integration and returning schema validation errors

We are using Spring Integration to process a JSON payload passed into a RESTful endpoint. As part of this flow we are using a filter to validate the JSON:

.filter(schemaValidationFilter, s -> s
    .discardFlow(f -> f
        .handle(message -> {
            throw new SchemaValidationException(message);
        }))
)

This works great. However, if the validation fails we want to capture the parsing error and return that to the user so they can act on the error. Here is the overridden accept method in the SchemaValidationFilter class:

@Override
public boolean accept(Message<?> message) {
  Assert.notNull(message);
  Assert.isTrue(message.getHeaders().containsKey(TYPE_NAME));

  String historyType = (String)message.getHeaders().get(TYPE_NAME);
  JSONObject payload = (JSONObject) message.getPayload();
  String jsonString = payload.toJSONString();

  try {
      ProcessingReport report = schemaValidator.validate(historyType, payload);
      return report.isSuccess();
  } catch (IOException | ProcessingException e) {
      throw new MessagingException(message, e);
  }

}

What we have done is in the catch block we throw a MessageException which seems to solve the problem. However this seems to break what a filter should do (simply return a true or false).

Is there a best practice for passing the error details from the filter to the client? Is the filter the right solution for this use case?

Thanks for your help! John


Source: (StackOverflow)

Json schema dynamic key validation

Facing an issue with schema validation.

schema :

{
    "type": "object",
    "$schema": "http://json-schema.org/draft-03/schema",
    "id": "#",
    "required": true,
    "patternProperties": {
        "^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$": {
            "type": "object",
            "required": true,
            "properties": {
                "_from": {
                    "id": "_from",
                    "type": "string",
                    "required": true
                },
                "message": {
                    "type": "object",
                    "id": "message",
                    "properties": {
                        "detail": {
                            "type": "string",
                            "id": "detail",
                            "required": true
                        },
                        "from": {
                            "type": "string",
                            "id": "from",
                            "required": true
                        }
                    }
                }
            }
        }
    }
}

json :

{
    "tom@example.com": {
        "_from": "giles@gmail.com",
        "message": {
            "from": "Giles@gmail.com",
            "detail": "AnyonewanttomeetmeinParis"
        }
    },
    "harry@example.com": {
        "_from": "giles@gmail.com",
        "message": {
            "from": "Giles@gmail.com",
            "detail": "AnyonewanttomeetmeinParis"
        }
    }
}

Here the key email address is dynamic, somehow it doesn't validate regex for email validation.

Can you please advise me to correct the schema.

I am validating using : http://json-schema-validator.herokuapp.com/index.jsp


Source: (StackOverflow)

Setting an Attribute as a "string" or null in JSON Schema with a maxLength

I'm trying to create a JSON schema that allows for a nullable attribute. For example, I want the following JSON to be valid:

{
 "some_name" : null
}

with the following schema:

{
  "type": "object",
  "properties": {
    "some_name": {
      "type": [
        "string",
        null
      ],
      "maxLength": 100
    }
  }
}

However, it's invalid as it thinks that "null" can't have a maxLength. Is there a good way to do this? I wish there was a "nullable" attribute, or something of the sort!


Source: (StackOverflow)

how to use jsonschema validation in angular js/rest web service architecture?

I am looking to design a client-side json validator through a json schema created for a server (Java backend), so it is important that I use the same schema. What plugins are useful for angularjs to implement json validation on the client?


Source: (StackOverflow)

No class found Exception while validating Json with JsonSchema

I am new to Java.

I am trying to validate a Json with JsonSchema. I have referred Java/Android - Validate String JSON against String schema.. I have tried with #Tihamer code and I am getting a JsonParserException which I have not used it.

Below is my 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 is the error

Exception in thread "main" java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/JsonParseException
    at com.github.fge.jackson.JsonLoader.<clinit>(JsonLoader.java:50)
    at JsonValidation.validation(JsonValidation.java:25)
    at JsonValidation.main(JsonValidation.java:16)
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.core.JsonParseException
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 3 more

I solved the previous error but now I am getting error like

Exception in thread "main" java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonFactory.requiresPropertyOrdering()Z
    at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:537)
    at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:448)
    at com.github.fge.jackson.JacksonUtils.newMapper(JacksonUtils.java:155)
    at com.github.fge.jackson.JacksonUtils.<clinit>(JacksonUtils.java:55)
    at com.github.fge.jackson.JsonNodeReader.<init>(JsonNodeReader.java:82)
    at com.github.fge.jackson.JsonLoader.<clinit>(JsonLoader.java:50)
    at com.github.fge.jsonschema.examples.Utils.loadResource(Utils.java:53)
    at JsonValidateTest.main(JsonValidateTest.java:19)

I have not used the objectMapper class but I am getting exception.


Source: (StackOverflow)