Giter Club home page Giter Club logo

jackson-json-reference's Introduction

jackson-json-reference

WARNING! Not being actively maintained.

Parent: Build Status Codecov

  • Core: Download Core
  • CLI:   Download CLI

JSON Reference implementation for Java, based on Jackson. Process references in JSON documents, such as in JSON Schema. Aims for but not limited to full spec compliance.

Features

  • Supports URLs & files.
  • Relative & absolute reference URIs.
  • Recursive expansion, with options for max depth and stop on circularity.
  • Custom object mappers, allowing Jackson features like JSON comments, YAML, etc.
  • Built-in support for YAML based on file extension detection.

Specs

Usage

File

File file = new File("src/test/resources/nest.json");
JsonNode node = (new JsonReferenceProcessor()).process(file);

URL

URL url = new URL("http://json-schema.org/schema");
JsonNode node = (new JsonReferenceProcessor()).process(url);

Settings

JsonReferenceProcessor processor = new JsonReferenceProcessor();

processor.setStopOnCircular(false); // default true

processor.setMaxDepth(2); // default 1, or set to -1 for no max depth

// Custom object mapper allowing comments.
processor.setMapperFactory(new ObjectMapperFactory() {
   @Override
   public ObjectMapper create(URL url) {
       //ObjectMapper objectMapper = DefaultObjectMapperFactory.instance.create(url);
       ObjectMapper objectMapper = new ObjectMapper();
       objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
       return objectMapper;
   }
});

JsonNode node = processor.process( /*...*/ );

Output

ObjectMapper mapper = new ObjectMapper();
mapper.writeValue(new File("out.json"), node);

Install

Maven

<dependencies>
    <dependency>
        <groupId>me.andrz.jackson</groupId>
        <artifactId>jackson-json-reference-core</artifactId>
        <version>0.3.2</version>
    </dependency>
</dependencies>

Gradle

repositories {
    mavenCentral()
}

dependencies {
    compile 'me.andrz.jackson:jackson-json-reference-core:0.3.2'
}

Manual

Download JAR(s) from Maven Central:

  • Core: Download Core
  • CLI:   Download CLI

License

See LICENSE.

Development

Publishing

If you need to bump the version of all projects in the multi-project:

mvn versions:set -DnewVersion=2.50.1-SNAPSHOT

Then be sure your build is up to date:

mvn compile

Now, use the Release Plugin (http://maven.apache.org/maven-release/maven-release-plugin/usage.html):

mvn release:prepare -DdryRun=true
mvn release:prepare

If you mess up:

mvn release:clean

Else:

mvn release:perform

jackson-json-reference's People

Contributors

andersdjohnson avatar benmccann avatar chris922 avatar kdombeck avatar slavaschmidt avatar splaw88 avatar zregvart avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

jackson-json-reference's Issues

[New feature] Support to generate back the structure from a JSON and references

Hey,
This library was exactly what I was looking for. However, does this support getting back the file structure given a single JSON (possibly with xref pointers) or a reference file?
If not, do you plan to support this?

Use case:
I have a service that accepts JSON as a zip file and we allow the user to provide the JSON using JSONReferences. However, the internal store can be modified by other means as well (UI, etc). While returning back the zip file, we need to merge the changes and return in the same format as provided by the user.
It would be great to have this feature.

Thanks

References in Arrays are resolved in wrong indexes

Hi,

there is an issue when putting reference in some element of an Array.
For example:
given json test.json:
[{"test": "0"},{"$ref": "external.json"},{"test": "2"}]
and external.json:
{"test": "1"}
results with:
[{"test": "1"},{"$ref": "external.json"},{"test": "2"}]

external json is resolved in first index of array and reference is still there
Is this resolvable, or in array there is some other way to place references?

License change?

Consider a less restrictive license. Look at licenses of dependencies.

Enable JsonParser Features like ALLOW_COMMENTS, ALLOW_YAML_COMMENTS

Currently there is no way to use the Jacksons Paser Features (e.g. ALLOW_COMMENTS, ALLOW_YAML_COMMENTS), because the JsonContext uses its own ObjectMapper.

I would recommend set the mapper via Constructor.

In this way it is possible to use the mapper of JsonReferenceProcessor the following way

JsonContext context = new JsonContext(this.mapper, file);

With that small changes you could

  • enable the Features for an ObjectMapper

  • inctect this mapper in JsonReferenceProcessor like before

    I am totally new github user. Is it possible to create that feature myself?

Kind regards

README little mistake

In the README file, there is a bizarre line:

JsonReference processor = new JsonReferenceProcessor();

Which I believe it should be:

JsonReferenceProcessor processor = new JsonReferenceProcessor();

So the type returned by the constructor matches the variable's type.

Destroys UNC paths after URI#resolve

UNC paths are destroyed after calling the URI#resolve method:

absoluteReferencedUrl = contextUrl.toURI().resolve(refUri).toURL();

Example:

final URI baseUri = new File("//SERVER/some/path").toURI();
System.out.println(baseUri); // -> file:////SERVER/some/path (UNC-Path)

final URI resolved = baseUri.resolve("file.json#");
System.out.println(resolved); // -> file:/SERVER/some/file.json# (no UNC-Path)

Maven Central

Do you have any plans to start publishing this library to Maven Central?

I'm currently working on a Swagger validation library for which it's necessary to be able to resolve JSON refs, so it'd be great to use this library. However, I'm reluctant to ship a lib with dependencies that can't be resolved without adding repositories, as this makes life difficult for folks whose only source of Maven deps is a corporate Nexus/Artifactory installation.

I'm planning to fork this and publish it to a group I'm able to release under for now. Please let me know if this is problematic for you in any way.

Thanks,
Tom

Json not being processed

I'm running this file via CLI but I just get the plain text claims. I'm doing something wrong

"claims": {
"claims": {
"claim-statement": {
"$t": "I\/We claim:"
},
"@lang": "EN",
"claim": [
{
"claim-text": {
"$t": ". A clip () for fastening a car seat cover onto a car seat, the clip () comprising:\n",
"b": [
{
"$t": "1"
},
{
"$t": "10"
},
{
"$t": "10"
}
],
"claim-text": [
{
"$t": "a head means () comprising a U-shaped holder () with a gripping means () at each end to receive and grasp a car seat cover; and",
"b": [
{
"$t": "11"
},
{
"$t": "11"
},
{
"$t": "11"
}
],
"i": [
{
"$t": "a"
},
{
"$t": "b"
}
]
},
{
"$t": "an insertion element () having a tip end, connected to the head means () via a midpoint element (), to be embedded in the car seat for fastening the car seat cover;",
"b": [
{
"$t": "13"
},
{
"$t": "11"
},
{
"$t": "12"
}
]
},
{
"$t": "characterised in that the midpoint element () is a truncated cone connecting the head means () with the insertion element (), wherein the clip () is inserted to a joining of the car seat cushion.",
"b": [
{
"$t": "12"
},
{
"$t": "11"
},
{
"$t": "13"
},
{
"$t": "10"
}
]
}
]
},
"@num": "00001",
"@id": "CLM-00001"
},
{
"claim-text": {
"$t": ". The clip () as claimed in , wherein the midpoint element () is bendable to 90°, thereby allowing different angles of insertion of the clip () onto the car seat.",
"b": [
{
"$t": "2"
},
{
"$t": "10"
},
{
"$t": "12"
},
{
"$t": "10"
}
],
"claim-ref": {
"$t": "claim 1",
"@idref": "CLM-00001"
}
},
"@num": "00002",
"@id": "CLM-00002"
},
{
"claim-text": {
"$t": ". The clip () as claimed in , wherein the clip () is made of stretchable material.",
"b": [
{
"$t": "3"
},
{
"$t": "10"
},
{
"$t": "10"
}
],
"claim-ref": {
"$t": "claim 1",
"@idref": "CLM-00001"
}
},
"@num": "00003",
"@id": "CLM-00003"
},
{
"claim-text": {
"$t": ". The clip () as claimed in , wherein the stretchable material is rubber.",
"b": [
{
"$t": "4"
},
{
"$t": "10"
}
],
"claim-ref": {
"$t": "claim 3",
"@idref": "CLM-00003"
}
},
"@num": "00004",
"@id": "CLM-00004"
},
{
"claim-text": {
"$t": ". The clip () as claimed in , wherein the insertion element () has a tip end heading downward.",
"b": [
{
"$t": "5"
},
{
"$t": "10"
},
{
"$t": "13"
}
],
"claim-ref": {
"$t": "claim 1",
"@idref": "CLM-00001"
}
},
"@num": "00005",
"@id": "CLM-00005"
}
],
"@load-source": "patent-office",
"@mxw-id": "PCLM181887614"
},
"@version": "1.0",
"@encoding": "UTF-8"
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.