JSON smart
Required dependency
<dependency>
<groupId>net.minidev</groupId>
<artifactId>json-smart</artifactId>
<version>2.5.2</version>
</dependency>
implementation 'net.minidev:json-smart:2.5.2'
The newest version is always supported.
Adapter classes are:
Provider node
The JsonNode abstraction wraps a concrete class from JSON/YAML library, which is called a "provider node." It is possible to interact with the API using provider nodes directly, but there is no type information at compile time, so please ensure that you are using the correct class.
Usage
Creating Validator instance
JsonNodeFactory factory = new JsonSmartNode.Factory();
Validator validator = new ValidatorFactory()
.withJsonNodeFactory(factory)
.createValidator();
Using custom JSONParser
JSONParser jsonParser = new JSONParser(MODE_JSON_SIMPLE);
JsonNodeFactory factory = new JsonSmartNode.Factory(jsonParser);
Validator validator = new ValidatorFactory()
.withJsonNodeFactory(factory)
.createValidator();
Converting String to JsonNode
JsonNodeFactory factory = new JsonSmartNode.Factory();
JsonNode jsonNode = factory.create("{}");
Converting provider node to JsonNode
Object providerNode = new JSONTokener("{}").nextValue();
JsonNodeFactory factory = new JsonSmartNode.Factory();
JsonNode jsonNode = factory.wrap(providerNode);
Using Validator with provider nodes
Object providerSchemaNode = new JSONParser(MODE_JSON_SIMPLE).parse("{}");
URI schemaUri = validator.registerSchema(providerSchemaNode);
Object providerInstanceNode = new JSONParser(MODE_JSON_SIMPLE).parse("true");
Validator.Result result = validator.validate(schemaUri, providerInstanceNode);
04 August 2025