Skip to content

Latest commit

 

History

History
129 lines (100 loc) · 4.22 KB

README.md

File metadata and controls

129 lines (100 loc) · 4.22 KB

jackson-json-reference

Bintray Build Status Codecov

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

// 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

<repositories>
    <repository>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <id>bintray-adjohnson916-maven</id>
        <name>bintray-adjohnson916-maven</name>
        <url>https://dl.bintray.com/adjohnson916/maven</url>
    </repository>
</repositories>

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

Gradle

repositories {
    maven {
        url 'https://dl.bintray.com/adjohnson916/maven'
    }
}

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

Manual

Download JAR(s) from BinTray:

License

See LICENSE.