Skip to content
This repository has been archived by the owner on Jan 4, 2020. It is now read-only.

markenwerk/java-utils-json-handler-text

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Text handler for JSON libraries

Build Status Coverage Status Dependency Status Maven Central Issues MIT License

Overview

This library provides text related JSON handlers for other JSON processing libraries.

Consult the documentation and the usage description for further information:

Maven

This library is hosted in the Maven Central Repository. You can use it with the following coordinates:

<dependency>
	<groupId>net.markenwerk</groupId>
	<artifactId>utils-json-handler-text</artifactId>
	<version>2.0.2</version>
</dependency>

Usage

Java text handler

An AppendingJavaTextJsonHandler is a JsonHandler that appends a text, that represents the described JSON document by mimicing the toString() behavior of Java collection classes, to an Appendable.

// a JsonDocument
JsonDocument document = ...

// writes a pretty printed json document into test.json  
Writer writer = new FileWriter(new File("test.json"));
document.handle(new AppendingJavaTextJsonHandler(writer));
writer.close();

The appended String for the example.json has the following content:

{null=null, boolean=true, long=-42, double=-23.42, array=[foo, bar]}

A JavaTextJsonHandler is a JsonHandler that creates a String, containing a text that represents the described JSON document by mimicing the toString() behavior of Java collection classes.

// a JsonDocument
JsonDocument document = ...

// returns a pretty printed json document  
String json = document.handle(new JavaTextJsonHandler(writer));

The returned String for the example.json has the following content:

{null=null, boolean=true, long=-42, double=-23.42, array=[foo, bar]}

JSON text handler

An AppendingJsonTextJsonHandler is a JsonHandler that appends a JSON text, that represents the described JSON document, to an Appendable.

// a JsonDocument
JsonDocument document = ...

// writes a pretty printed json document into test.json  
Writer writer = new FileWriter(new File("test.json"));
document.handle(new AppendingJsonTextJsonHandler(writer));
writer.close();

The appended String for the example.json has the following content:

{
    "null" : null,
    "boolean" : true,
    "long" : -42,
    "double" : -23.42,
    "array" : [
        "foo",
        "bar"
    ]
}

A JsonTextJsonHandler is a JsonHandler that creates a String, containing a JSON text that represents the described JSON document.

// a JsonDocument
JsonDocument document = ...

// returns a pretty printed json document  
String json = document.handle(new JsonTextJsonHandler(writer));

The returned String for the example.json has the following content:

{
    "null" : null,
    "boolean" : true,
    "long" : -42,
    "double" : -23.42,
    "array" : [
        "foo",
        "bar"
    ]
}

About

Text handler for JSON processing libraries for Java

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages