org.brutusin:json

Brutusin common utilities

License

License

Categories

Categories

JSON Data
GroupId

GroupId

org.brutusin
ArtifactId

ArtifactId

json
Last Version

Last Version

1.4.1
Release Date

Release Date

Type

Type

jar
Description

Description

org.brutusin:json
Brutusin common utilities
Project URL

Project URL

https://github.com/brutusin/json
Source Code Management

Source Code Management

https://github.com/brutusin/json

Download json

How to add to project

<!-- https://jarcasting.com/artifacts/org.brutusin/json/ -->
<dependency>
    <groupId>org.brutusin</groupId>
    <artifactId>json</artifactId>
    <version>1.4.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.brutusin/json/
implementation 'org.brutusin:json:1.4.1'
// https://jarcasting.com/artifacts/org.brutusin/json/
implementation ("org.brutusin:json:1.4.1")
'org.brutusin:json:jar:1.4.1'
<dependency org="org.brutusin" name="json" rev="1.4.1">
  <artifact name="json" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.brutusin', module='json', version='1.4.1')
)
libraryDependencies += "org.brutusin" % "json" % "1.4.1"
[org.brutusin/json "1.4.1"]

Dependencies

compile (1)

Group / Artifact Type Version
org.brutusin : commons jar 1.4.0

test (1)

Group / Artifact Type Version
junit : junit jar 4.10

Project Modules

There are no modules declared in this project.

org.brutusin:json Build Status Maven Central Latest Version

org.brutusin:json is a service provider interface (SPI) that aggregates all the JSON-related functionality needed by the rest of Brutusin modules.

This module defines the general contract required to any implementing JSON service provider, allowing to use different pluggable implementations and decoupling client modules from them.

Table of Contents:

Maven dependency

<dependency>
    <groupId>org.brutusin</groupId>
    <artifactId>json</artifactId>
    <version>${json.version}</version>
</dependency>

Click here to see the latest available version released to the Maven Central Repository.

If you are not using maven and need help you can ask here.

SPI

JsonCodec is the single entry point to the framework. It defines a SPI (service provider interface) that is implemented by pluggable service providers. Clients of the service make use of it by calling:

JsonCodec.getInstance()

JsonCodec provides three types of operations: Data operations (inherited from JsonDataCodec), schema operations (inherited from JsonSchemaCodec) and path expression operations (via compile(String expression))

Class diagram

Data

Data methods declared in JsonDataCodec offer Object/JSON binding (get JSON representations from objects and object tree instantiation from JSON data) and a generic API to interact with JSON data in a generic way (JsonNode).

JSON Schema

A JSON schema (specifications) is a JSON document that describes the structure of other JSON documents.

Schemas are represented by the interface JsonSchema, and instantiated by the methods in JsonSchemaCodec, either by parsing the JSON Schema document (parseSchema(String json)) and by reflection from a Class instance (getSchema(Class<T> clazz)).

This module adheres to the JSON schema specification defined in http://brutusin.org/json/json-schema-spec

Validation

Schemas are useful both for describing the structure and for validating JsonSchema.validate(JsonNode node) that JSON data complies the constraints imposed by them.

Path expressions

See extension specification.

See ExpressionTest for some examples.

Java Annotations

Schema generation annotations

The following annotations can be used to customize schema generation, and must be supported by all providers:

Standard schema properties

  • @JsonProperty. Lets specify standard schema properties like required, default, enum, title, description,...

Custom schema properties

  • @IndexableProperty. Adds custom "index":"index" or "index":"facet" properties to the schema generated.
  • @DependentProperty. Adds custom "dependsOn":<property name array> properties to the schema generated.

Streaming API

This SPI supports binary attachments in JSON data, a feature that enables serialization/deserialization of properties of type InputStream or MetaDataInputStream.

JsonStreamCodec declares the SPI functionality related with binary attachments.

Service Providers

Service providers are modules implementing this SPI and registering themselves via the ServiceLoader standard facility.

JUnit tests for implementing providers

All service providers must pass the JUnit tests included in this module. In order to that, the following maven dependence has to be included

<dependency>
     <groupId>org.brutusin</groupId>
     <artifactId>json</artifactId>
     <type>test-jar</type>
     <version>${json.version}</version>
     <scope>test</scope>
</dependency>

and predefined tests have to be extended by the service provider tests.

Reference implementation

See org.brutusin:json-provider for a reference implementation.

ToDos

  • Standard annotations also for data binding (not only for schema customization), supporting property ordering, ignoring properties...
  • Since annotation inheritance is not allowed in java, introduce some mechanism for schema extension (allowing non-standard schema properties) to be used by the service providers. This also would help to move @IndexableProperty (aimed at being used by org.brutuisn:flea-db) and @DependentProperty out of this module.
  • Path expressions: Add more features similar to those in XPath like:
    • Filters
    • Functions

See also

Support bugs and requests

https://github.com/brutusin/json/issues

Authors

Contributions are always welcome and greatly appreciated!

License

Apache License, Version 2.0

org.brutusin

brutusin.org

Best friendly software libraries. In loving memory of Brutus

Versions

Version
1.4.1
1.4.0
1.3.1
1.3.0
1.2.0
1.1.1
1.1.0
1.0.3
1.0.2
1.0.1
1.0.0