Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the fastest way to deserialize JSON in java

Tags:

java

json

I'm wondering what is the fastest way to parse json in JAVA ?

  • Getting a default object graph using the library built in Array, and Object objects
  • Getting a custom object graph using your own java bean

Thanks

like image 933
AdrienBrault Avatar asked Apr 26 '13 07:04

AdrienBrault


People also ask

What is the fastest JSON parser?

Performance results To our knowledge, simdjson is the first fully-validating JSON parser to run at gigabytes per second (GB/s) on commodity processors. It can parse millions of JSON documents per second on a single core.

Is JSON deserialization slow?

The expected latency when downloading anything from a server to a client should increase as the size of the file increases.

How do I deserialize a JSON file?

A common way to deserialize JSON is to first create a class with properties and fields that represent one or more of the JSON properties. Then, to deserialize from a string or a file, call the JsonSerializer. Deserialize method.

What is deserialization of JSON in Java?

Deserialization is transforming the data from a file or stream back into an object to be used in your application. This can be binary data or structured data like JSON and XML. Deserialization is the opposite of serialization, which transforms objects into byte streams or structured text.


2 Answers

Mapping parsed JSON to Java bean involves additional steps, so using the raw interface (e.g. the streaming API of Jackson) will be faster. This way, you can also read until have what you need and stop parsing.

In response to @sikorski
From Jackson Wiki:

Data binding is built using Streaming API as the underlying JSON reading/writing system: as such it has high-performance [...], but has some additional overhead compared to pure streaming/incremental processing

This is pretty much inevitable. If you are writing a generic Jackson parser, you obviously can't use custom types in it. Therefore it follows that you'll have to construct the custom type after you read the JSON with the generic parser, and hence the generic parser will be faster. It's worth noting though that such overhead is very small and almost never something you need to optimize away.

like image 97
Enno Shioji Avatar answered Sep 26 '22 15:09

Enno Shioji


Well, The newest and wickedly Fastest one is Boon Json. I used it in my project and got an improvement of 20X. I actually got scared and double checked to see if Library is functionally correct. Thankfully, it is :) :) Boon has built in methods to serialize and de-serialize from/to Java Array/Maps and Custom Beans.
More Here : https://github.com/RichardHightower/boon

like image 29
RamNat Avatar answered Sep 24 '22 15:09

RamNat