Skip to content

tomalloc/jackson-datatype-fastjson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Usage

Maven dependency

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

<dependency>
    <groupId>com.github.tomalloc</groupId>
    <artifactId>jackson-datatype-fastjson</artifactId>
  <version>2.11.4</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.fastjson.FastJsonModule;

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

This will ensure that basic datatype of com.alibaba.fastjson 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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages