Support for org.json data types, to ease migration out of code that uses them
Switch branches/tags
jackson-datatype-json-org-2.9.7 jackson-datatype-json-org-2.9.6 jackson-datatype-json-org-2.9.5 jackson-datatype-json-org-2.9.4 jackson-datatype-json-org-2.9.3 jackson-datatype-json-org-2.9.2 jackson-datatype-json-org-2.9.1 jackson-datatype-json-org-2.9.0 jackson-datatype-json-org-2.9.0.pr4 jackson-datatype-json-org-2.9.0.pr3 jackson-datatype-json-org-2.9.0.pr2 jackson-datatype-json-org-2.9.0.pr1 jackson-datatype-json-org-2.8.11 jackson-datatype-json-org-2.8.10 jackson-datatype-json-org-2.8.9 jackson-datatype-json-org-2.8.8 jackson-datatype-json-org-2.8.7 jackson-datatype-json-org-2.8.6 jackson-datatype-json-org-2.8.5 jackson-datatype-json-org-2.8.4 jackson-datatype-json-org-2.8.3 jackson-datatype-json-org-2.8.2 jackson-datatype-json-org-2.8.1 jackson-datatype-json-org-2.8.0 jackson-datatype-json-org-2.8.0.rc2 jackson-datatype-json-org-2.8.0.rc1 jackson-datatype-json-org-2.7.9 jackson-datatype-json-org-2.7.8 jackson-datatype-json-org-2.7.7 jackson-datatype-json-org-2.7.6 jackson-datatype-json-org-2.7.5 jackson-datatype-json-org-2.7.4 jackson-datatype-json-org-2.7.3 jackson-datatype-json-org-2.7.2 jackson-datatype-json-org-2.7.1 jackson-datatype-json-org-2.7.0 jackson-datatype-json-org-2.7.0-rc3 jackson-datatype-json-org-2.7.0-rc2 jackson-datatype-json-org-2.7.0-rc1 jackson-datatype-json-org-2.6.7 jackson-datatype-json-org-2.6.6 jackson-datatype-json-org-2.6.5 jackson-datatype-json-org-2.6.4 jackson-datatype-json-org-2.6.3 jackson-datatype-json-org-2.6.2 jackson-datatype-json-org-2.6.1 jackson-datatype-json-org-2.6.0 jackson-datatype-json-org-2.6.0-rc4 jackson-datatype-json-org-2.6.0-rc3 jackson-datatype-json-org-2.6.0-rc2 jackson-datatype-json-org-2.6.0-rc1 jackson-datatype-json-org-2.5.4 jackson-datatype-json-org-2.5.3 jackson-datatype-json-org-2.5.2 jackson-datatype-json-org-2.5.1 jackson-datatype-json-org-2.5.0 jackson-datatype-json-org-2.5.0-rc1 jackson-datatype-json-org-2.4.6 jackson-datatype-json-org-2.4.5 jackson-datatype-json-org-2.4.4 jackson-datatype-json-org-2.4.3 jackson-datatype-json-org-2.4.2 jackson-datatype-json-org-2.4.1 jackson-datatype-json-org-2.4.0 jackson-datatype-json-org-2.4.0-rc3 jackson-datatype-json-org-2.4.0-rc2 jackson-datatype-json-org-2.3.5 jackson-datatype-json-org-2.3.4 jackson-datatype-json-org-2.3.3 jackson-datatype-json-org-2.3.2 jackson-datatype-json-org-2.3.1 jackson-datatype-json-org-2.3.0 jackson-datatype-json-org-2.3.0-rc1 jackson-datatype-json-org-2.2.3 jackson-datatype-json-org-2.2.2 jackson-datatype-json-org-2.2.1 jackson-datatype-json-org-2.2.0 jackson-datatype-json-org-2.1.5 jackson-datatype-json-org-2.1.2 jackson-datatype-json-org-2.1.1 jackson-datatype-json-org-2.1.0 jackson-datatype-json-org-2.0.2 jackson-datatype-json-org-2.0.0 jackson-datatype-json-org-2.0.0-RC3 jackson-datatype-json-org-2.0.0-RC2 jackson-datatype-json-org-2.0.0-RC1 jackson-datatype-json-org-1.8.0 jackson-datatype-json-org-0.9.3 jackson-datatype-json-org-0.9.2
Nothing to show
Clone or download

README.md

Project to build Jackson extension module (jar) to support datatypes of "json org" JSON library

Status

Build Status Maven Central Javadoc

Module is fully usable and officially released.

Usage

Maven dependency

To use module (version 2.x) on Maven-based projects, use following dependency:

<dependency>
  <groupId>com.fasterxml.jackson.datatype</groupId>
  <artifactId>jackson-datatype-json-org</artifactId>
  <version>2.9.0</version>
</dependency>

(or whatever version is most up-to-date at the moment)

Registering module

To use the the Module in Jackson, simply register it with the ObjectMapper instance:

// import com.fasterxml.jackson.datatype.jsonorg.JsonOrgModule;

ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JsonOrgModule());

This will ensure that basic datatype of org.json package can be read and written using Jackson data-binding functionality.

Data conversions

After registering the module, you can read and write JSON to/from org.json.JSONObject similar to handling custom POJOs or standard JDK types:

JSONObject ob = mapper.readValue(json, JSONObject.class); // read from a source
String json = mapper.writeValue(ob); // output as String

As well as do conversion to/from POJOs:

MyValue value = mapper.convertValue(jsonObject, MyValue.class);
JSONObject jsonObject = mapper.convertValue(value, JSONObject.class);

or to/from Tree Model:

JsonNode root = mapper.valueToTree(jsonObject);
jsonObject = mapper.treeToValue(root, JSONObject.class);

Similarly, you can read/write/convert-to/convert-from JSONArray instead of JSONObject.