Differences GSON vs JSON
What is GSON?
GSON adalah library racikan Google untuk melakukan serialisasi dan deserialisasi data JSON dengan mudah. Serialisasi adalah proses mengubah objek Java menjadi JSON, sedangkan deserialisasi adalah proses mengubah JSON menjadi objek Java. Serialisasi dan deserialisasi biasanya dilakukan saat kita bekerja dengan webservice.
We need serialization because the hard disk or network infrastructure are hardware component and we cannot send java objects because it understands just bytes and not java objects.
Serialization is used in the cases where you want to save an object state and convert that object into byte stream, objects need to be serialized. While you're running your application, all of its objects are stored in memory (heap memory). When you exit, that memory gets reclaimed by the operating system, and your program essentially 'forgets' everything that happened while it was running. In these types of situation, you can use serialization by letting your application save objects to disk so it can read them back the next time it starts. If your application is going to provide any way saving or sharing a previous state, you'll need some form of serialization.
Whenever an object has to send over the network, those objects should be serialized. For example, if you have two machines that are running the same code, and they need to communicate, an easy way is for one machine to build an object with information that it would like to transmit, and then serialize that object to the other machine. It's not the best method for communication, but it gets the job done with serialization.
-------------------------------------------------------------------------------------------------------
Lalu Apa itu JSON?
JSON (JavaScript Object Notation) adalah sebuah format data yang digunakan untuk pertukaran dan penyimpanan data. JSON merupakan bagian (subset) dari JavaScript. JSON bisa dibaca dengan berbagai macam bahasa pemrograman seperti C, C++, C#, Java, JavaScript Perl, Python, dan banyak lagi.
-Struktur Dasar JSON-
Hal ini membuat JSON menjadi bahasa yang ideal untuk pertukaran data antar aplikasi. JSON bahkan mendominasi pendahulunya si XML (eXtensible Markup Language). Jika dibandingkan dengan XML, JSON lebih sederhana dan mudah dibaca.
Berikut ini contoh perbedaan antara penulisan kode XML dan JSON.
Berikut ini beberapa contoh penerapan JSON :
- JSON sebagai format untuk bertukar data client dan server atau antar aplikasi. Contoh: RESTful API.
- JSON sebagai tempat menyimpan data, contoh: Database Mongodb
- JSON digunakan untuk menyimpan konfigurasi project, contoh: file composer.json pada project PHP dan package.json pada Node.js
- JSON digunakan untuk menyimpan konfigurasi dan pemyimpan data pada Hugo
- JSON digunakan untuk menyimpan data manifest
- dan lain-lain.
-----------------------------------------------------------------------------------------------------
References :
Comments
Post a Comment