Coder Social home page Coder Social logo

nagramachandran / jackson-datatype-json-org Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fasterxml/jackson-datatype-json-org

0.0 2.0 0.0 339 KB

Support for org.json data types, to ease migration out of code that uses them

Java 100.00%

jackson-datatype-json-org's Introduction

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.

jackson-datatype-json-org's People

Contributors

arturdryomov avatar benmccann avatar cowtowncoder avatar frankwis avatar mpoindexter avatar prb avatar squiddle avatar valery1707 avatar

Watchers

 avatar  avatar

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.