Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do Jackson and Gson directly implement the standard JSR-353?

I couldn't find an answer to my question on the net (maybe I did not search well enough, since I am still a novice on this).

Could anyone tell me if Jackson and Gson implement the standard JSR 353: Java™ API for JSON Processing. I would like to write using standard code.

like image 617
maher.belkh Avatar asked Jan 16 '15 10:01

maher.belkh


People also ask

What is the difference between Jackson and GSON?

If you're concerned about parsing speed for your JSON library, choose Jackson for big files, GSON for small files, and JSON. simple for handling both.

What JSR 353?

JSON support in java is delivered trough the new API for JSON Processing (JSON-API), which was standardized in JSR 353. this specification defines a API to parse, generate, transform and query JSON documents.

What is the difference between JSON and Jackson?

JSON is a data format. Jackson is a Java library that can parse JSON.

Is GSON faster than Jackson?

Looking at the average result for all the test runs across all the files, GSON is the winner here, with JSON. simple and JSONP taking a distinct second and third place, respectively. Jackson came in 2nd to last. So despite not being the fastest on any single file, JSON.


2 Answers

This link has the reply (apparently by the Jackson founder), and it essentially says that Jackson doesn't implement the JSR:

Reply by Tatu Saloranta on January 26, 2014 at 8:21pm

I am not a big fan of JSR-353 (I consider it a big fail) and unless something drastic happens, Jackson core will not implement JSR-353. There is no benefit from data-binding to use it; both because implementations do not bring anything to table (none are particularly fast), nor implement all that databind needs (base64 encoding, multi-format support capabilities) -- and worst of all ALL existing (de)serializers would need to be rewritten use new, less capable API. And baseline for Jackson would need to become Java 8. So I see no upside.

However, the reverse is possible; it is possible to have a JSR-353 implementation based on Jackson streaming package, and this has been done already:

https://github.com/pgelinas/jackson-javax-json.

Or, to make Jackson capable of reading/writing JSR-353 JSON object types, a simple datatype module is needed. I wrote one a while back:

https://github.com/FasterXML/jackson-datatype-jsr353

So if Java developers end up following "the standard" track, Jackson can play along.

Google didn't (couldn't?) vote on the JSR, and I couldn't find anything on Gson's roadmap either to suggest that they'd want to comply.

like image 162
Pradyumna Avatar answered Oct 10 '22 15:10

Pradyumna


tl;dr

Use:

  • JSON-P
  • JSON-B

Update

The other two Answers are correct, but outdated. As they explain, Jackson does not directly implement any JSR.

However:

  • There is a project providing a datatype module to help make Jackson more compatible with JSR 353: jackson-datatype-jsr353.
  • JSR 353 is superseded by JSR 374: Java™ API for JSON Processing 1.1.
  • The JCP continued work on JSON support, for processing of JSON as well as binding yielding the pair of JSRs: 374 JSON-P & 367 JSON-B.
    • JSR 374 defines JSON processing (JSON-P).
      • See project page for JSON-P.
      • A reference implementation can be found in Glassfish, the reference implementation of Jakarta EE (formerly known as Java EE).
    • JSR 367 provides binding capabilities (JSON-B).
      • See the project page for JSON-B.
      • Yasson is the reference implementation.

So you may indeed now write in standard code using JSON libraries other than Jackson.

like image 29
Basil Bourque Avatar answered Oct 10 '22 16:10

Basil Bourque