6.json Notes
6.json Notes
JSON
======
Ex:
{
"id" : 101,
"name" : "Ashok",
"phno" : 12345,
"gender" : "Male"
}
=> Distributed applications will use JSON data for request & response
=========================================
Working with JSON in Java Applications
==========================================
=> To work with JSON in Java app, we have third party libraries
a) Jackson
b) Gson
=> By using above libraries we can convert JSON data to Java Object and vice versa
jackson/gson
java obj <----------------------> json data
=> The process of converting json data to java obj is called as de-serialization.
==============
Jackson API
==============
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.17.0</version>
</dependency>
===================================================================================
===
public class App {
===================================================================================
====
===========
GSON API
===========
-----------------------------------------------
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
---------------------------------------------
gson.toJson(Object obj);
gson.fromJson(File file);