com.cedarsoftware:json-io 4.9.12

Java JSON serialization

Homepage: https://github.com/jdereg/json-io

Platform: Maven

Language: Groovy

License: Apache-2.0

Repository: scm:git:git://github.com/jdereg/json-io.git

View on registry: http://search.maven.org/#artifactdetails%7Ccom.cedarsoftware%7Cjson...


json-io

Build Status Maven Central Javadoc

Perfect Java serialization to and from JSON format (available on Maven Central). To include in your project:

<dependency>
  <groupId>com.cedarsoftware</groupId>
  <artifactId>json-io</artifactId>
  <version>4.9.12</version>
</dependency>

json-io consists of two main classes, a reader (JsonReader) and a writer (JsonWriter). json-io eliminates the need for using ObjectInputStream / ObjectOutputStream to serialize Java and instead uses the JSON format.

json-io does not require that Java classes implement Serializable or Externalizable to be serialized, unlike the JDK's ObjectInputStream / ObjectOutputStream. It will serialize any Java object graph into JSON and retain complete graph semantics / shape and object types. This includes supporting private fields, private inner classes (static or non-static), of any depth. It also includes handling cyclic references. Objects do not need to have public constructors to be serialized. The output JSON will not include transient fields, identical to the ObjectOutputStream behavior.

json-io does not depend on any 3rd party libraries, has extensive support for Java Generics, and allows extensive customization.

###A few advantages of json-io over Google's gson library:

  • gson will fail with infinite recursion (StackOverflowError) when there is a cycle in the input data. Illustrated here.
  • gson cannot handle non-static inner classes. Illustrated here.
  • gson cannot handle hetereogeneous Collections, Object[], or Maps. Illustrated here.
  • gson cannot handle Maps with keys that are not Strings. Illustrated here.

Format

json-io uses proper JSON format. As little type information is included in the JSON format to keep it compact as possible. When an object's class can be inferred from a field type or array type, the object's type information is left out of the stream. For example, a String[] looks like ["abc", "xyz"].

When an object's type must be emitted, it is emitted as a meta-object field "@type":"package.class" in the object.
When read, this tells the JsonReader what class to instantiate. (@type output can be turned off - see User Guide).

If an object is referenced more than once, or references an object that has not yet been defined, (say A points to B, and B points to C, and C points to A), it emits a "@ref":n where 'n' is the object's integer identity (with a corresponding meta entry "@id":n defined on the referenced object). Only referenced objects have IDs in the JSON output, reducing the JSON String length.

Performance

json-io was written with performance in mind. In most cases json-io is faster than the JDK's ObjectInputStream / ObjectOutputStream. As the tests run, a log is written of the time it takes to serialize / deserialize and compares it to ObjectInputStream / ObjectOutputStream (if the static variable _debug is true in TestUtil).

###User Guide

Pretty-Printing JSON

Use JsonWriter.formatJson() API to format a passed in JSON string to a nice, human readable format. Also, when writing JSON data, use the JsonWriter.objectToJson(o, args) API, where args is a Map with a key of JsonWriter.PRETTY_PRINT and a value of 'true' (boolean or String). When run this way, the JSON written by the JsonWriter will be formatted in a nice, human readable format.

RESTful support

json-io can be used as the fundamental data transfer method between a Javascript / JQuery / Ajax client and a web server in a RESTful fashion.

See json-command-servlet for a light-weight servlet that processes REST requests.

Noteworthy

For useful Java utilities, check out java-util

Featured on json.org.

Revision History


Sponsors

Alt text

YourKit supports open source projects with its full-featured Java Profiler. YourKit, LLC is the creator of YourKit Java Profiler and YourKit .NET Profiler, innovative and intelligent tools for profiling Java and .NET applications.

Intellij IDEA from JetBrains Intellij IDEA


###License

Copyright (c) 2007 Cedar Software LLC.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

by John DeRegnaucourt

Releases

4.9.12 March 30, 2017
4.9.11 March 28, 2017
4.9.10 March 13, 2017
4.9.9 February 22, 2017
4.9.8 February 15, 2017
4.9.7 February 02, 2017
4.9.6 January 13, 2017
4.9.5 January 03, 2017
4.9.4 December 31, 2016
4.9.3 December 31, 2016
See all 82 releases

Project Statistics

SourceRank 14
Dependencies 0
Dependent projects 2
Dependent repositories 109
Total releases 82
Latest release
First release
Stars 192
Forks 70
Watchers 30
Contributors 20
Repo Size: 2.69 MB

Top Contributors See all

Cedar Software Francis Upton IV the-best-dev Faisal Hameed Kai Hufenbach Dan Armbrust sgandon Waldemar Reusch kkalisz kpartlow Daniel Darabos William Delanoue lance0428 pedrocpneto dtracers Dave Loyall Alvaro Mike Davis Josh Snyder Richard Kovacs

Something wrong with this page? Make a suggestion

Export .ABOUT file for this library

Last synced: 2017-03-27 18:18:59 UTC

Login to resync this project