Lots of improvements and fixes in preparation to add JSON schema validation.
It does add the @Validation annotation to declare the validation but lacks the code to execute it.
This will be in a later release. Also the @Validation should be considered experimental/preview.
New Features
JsonSchemaException is thrown from schema validation (both JSON schema and the simpler form provided by asObject)
A JsonValue can now be validated against JSON schema definition using validate. The JSON schema can be defined as a combination of a new @Validation annotation to put on types and methods as well as reading a JSON schema definition from a string. This, for now, only supports the validation part of JSON schema standard.
A GetListener for the JsonNode tree that is called with all path lookups. This was needed to be able to "reverse engineer" the property looked up by default methods in JsonObjects (which is otherwise in-transparent).
Changes
JsonPathException now extends NoSuchElementException and is thrown instead of NoSuchElementException in the API (that excludes JDK APIs like iterators)
JsonPathException now contains the path that does not exist
JsonObject#asObject now throws JsonPathException, JsonTreeException and JsonSchemaException depending on the reason the operation failed
all JSON API specific exception classes are declared final
Fixes
JsonMixed#of(JsonNode) now calles extract to make sure to base the new tree on just the given value (not its root)
JsonNumber#intValue(int) with default now returns the default if the node is defined as JSON null
JsonNumber#number(T): with default now returns the default if the node is defined as JSON null
JsonString#string(String): existing node defined as JSON null now results in provided default value
JsonBoolean#booleanValue(boolean): with default now returns the default if the node is defined as JSON null
New Methods
JsonArray#forEach(Consumer): process elements with consumer
JsonValue#asType(): get the current proxy API type
JsonValue#isNumber(): check if node is defined and a number
JsonValue#isInteger(): check if node is defined and a number without or with zero fraction
JsonValue#isString(): check if node is defined and a string
JsonValue#isBoolean(): check if node is defined and a boolean
JsonMap#keys(Set): map keys with default in case the map is undefined
JsonMap#forEach(BiConsumer): process entries with consumer
JsonMixed#ofNonStandard(String): create tree from JSON string which is not standard conform (single quotes)
JsonNumber#integer(): get value as Integer (allows null in constant to intValue())
JsonValue#validate(): validate schema with current asType() schema
JsonValue#validate(Class): validate schema with the given schema
JsonObject#has(List): check for a list of properties to exist in an object
JsonNode#ofNonStandard(String): create trees with lenient parsing
JsonNode#of(String,GetListener): create a tree with a listener
JsonValue#toListFromVarargs: get a List<T> from a node that is either simple or an array of simple nodes
Chores
corrected lots of javadoc on the thrown exceptions
removed Java 8 proxy workaround (Java 8 is no longer supported)
use JsonMixed.of and JsonMixed.ofNonStandard in tests instead of helper
use assertThrowsExactly over asertThrows where no sub-types are expected
Summary
Lots of improvements and fixes in preparation to add JSON schema validation. It does add the
@Validation
annotation to declare the validation but lacks the code to execute it. This will be in a later release. Also the@Validation
should be considered experimental/preview.New Features
JsonSchemaException
is thrown from schema validation (both JSON schema and the simpler form provided byasObject
)JsonValue
can now be validated against JSON schema definition usingvalidate
. The JSON schema can be defined as a combination of a new@Validation
annotation to put on types and methods as well as reading a JSON schema definition from a string. This, for now, only supports the validation part of JSON schema standard.GetListener
for theJsonNode
tree that is called with all path lookups. This was needed to be able to "reverse engineer" the property looked up bydefault
methods inJsonObject
s (which is otherwise in-transparent).Changes
JsonPathException
now extendsNoSuchElementException
and is thrown instead ofNoSuchElementException
in the API (that excludes JDK APIs like iterators)JsonPathException
now contains the path that does not existJsonObject#asObject
now throwsJsonPathException
,JsonTreeException
andJsonSchemaException
depending on the reason the operation failedfinal
Fixes
JsonMixed#of(JsonNode)
now callesextract
to make sure to base the new tree on just the given value (not its root)JsonNumber#intValue(int)
with default now returns the default if the node is defined as JSONnull
JsonNumber#number(T)
: with default now returns the default if the node is defined as JSONnull
JsonString#string(String)
: existing node defined as JSON null now results in provided default valueJsonBoolean#booleanValue(boolean)
: with default now returns the default if the node is defined as JSONnull
New Methods
JsonArray#forEach(Consumer)
: process elements with consumerJsonValue#asType()
: get the current proxy API typeJsonValue#isNumber()
: check if node is defined and a numberJsonValue#isInteger()
: check if node is defined and a number without or with zero fractionJsonValue#isString()
: check if node is defined and a stringJsonValue#isBoolean()
: check if node is defined and a booleanJsonMap#keys(Set)
: map keys with default in case the map is undefinedJsonMap#forEach(BiConsumer)
: process entries with consumerJsonMixed#ofNonStandard(String)
: create tree from JSON string which is not standard conform (single quotes)JsonNumber#integer()
: get value asInteger
(allows null in constant tointValue()
)JsonValue#validate()
: validate schema with currentasType()
schemaJsonValue#validate(Class)
: validate schema with the given schemaJsonObject#has(List)
: check for a list of properties to exist in an objectJsonNode#ofNonStandard(String)
: create trees with lenient parsingJsonNode#of(String,GetListener)
: create a tree with a listenerJsonValue#toListFromVarargs
: get aList<T>
from a node that is either simple or an array of simple nodesChores
JsonMixed.of
andJsonMixed.ofNonStandard
in tests instead of helperassertThrowsExactly
overasertThrows
where no sub-types are expectedAutomatic Testing