Raja has Published 469 Articles

How to deserialize a JSON array to list generic type in Java?

raja

raja

Updated on 06-Jul-2020 11:38:01

2K+ Views

The Gson library provides a class called com.google.gson.reflect.TypeToken to store generic types by creating a Gson TypeToken class and pass the class type. Using this type, Gson can able to know the class passed in the generic class.Syntaxpublic class TypeToken extends ObjectWe can deserialize a JSON array to a generic type of list in ... Read More

How can we add a JSONArray within JSONObject in Java?

raja

raja

Updated on 04-Jul-2020 08:50:58

5K+ Views

A JSONObject can parse text from a String to produce a map-like object and a JSONArray can parse text from a String to produce a vector-like object. We can also add a JSONArray within JSONObject by first creating a JSONArray with few items and add these array of items to the put() ... Read More

How can we decode a JSON object in Java?

raja

raja

Updated on 04-Jul-2020 06:27:24

3K+ Views

A JSON is a lightweight, text-based and language-independent data exchange format. A JSON can represent two structured types like objects and arrays. We can decode a JSON object using JSONObject and JSONArray from json.simple API. A JSONObject works as a java.util.Map whereas JSONArray works as a java.util.List.In the below example, we can decode a JSON object.Exampleimport org.json.simple.*; import ... Read More

How can we encode a JSON object in Java?

raja

raja

Updated on 04-Jul-2020 05:58:28

3K+ Views

A JSONObject is a subclass of java.util.HashMap where no order is provided. We can also use the strict ordering of elements as well with the help of the JSONValue.toJSONString(map) method i.e. by the implementation of java.util.LinkedHashMap.We can encode a JSON object in the below two examples.Example import java.util.*; import org.json.simple.JSONObject; public class ... Read More

How can we convert a map to the JSON object in Java?

raja

raja

Updated on 04-Jul-2020 05:51:35

9K+ Views

The JSON is a lightweight, text-based and language-independent data exchange format. The JSON can represent two structured types like objects and arrays. An object is an unordered collection of key/value pairs and an array is an ordered sequence of values. We can convert a Map to JSON object using the toJSONString() method(static) of org.json.simple.JSONValue. It has two ... Read More

How can we merge two JSON objects in Java?

raja

raja

Updated on 04-Jul-2020 05:40:36

17K+ Views

A JSON is a lightweight data-interchange format and the format of JSON is a key with value pair. The JSONObject can parse a text from a String to produce a map-like object and supports java.util.Map interface. We can use org.json.simple.JSONObject to merge two JSON objects in Java.We can merge two JSON ... Read More

How can we add a JSONArray to JSONObject in Java?

raja

raja

Updated on 04-Jul-2020 05:36:04

19K+ Views

The JSON is a text-based format for exchanging data. It is a lightweight component and language independent. We can also add a JSONArray to JSONObject. We need to add a few items to an ArrayList first and pass this list to the put() method of JSONArray class and finally add this array to JSONObject using the put() method. Exampleimport org.json.*; ... Read More

How can we write JSON objects to a file in Java?

raja

raja

Updated on 04-Jul-2020 05:35:31

2K+ Views

The JSON is one of the widely used data-interchange formats and is a lightweight and language independent. The json.simple is a lightweight JSON processing library that can be used to write JSON files and it can be used to encode or decode JSON text and fully compliant with JSON specification(RFC4627). In order to read a JSON file, ... Read More

How can we convert a JSON string to a JSON object in Java?

raja

raja

Updated on 03-Jul-2020 14:06:49

6K+ Views

The JSON stands for JavaScript Object Notation and it can be used to transfer and storage of data.  The JSONObject can parse text from a String to produce a map-like object. The object provides methods for manipulating its contents, and for producing a JSON compliant object serialization. The JSONArray can parse text from a String ... Read More

How to display a JFrame to the center of a screen in Java?

raja

raja

Updated on 03-Jul-2020 13:39:50

22K+ Views

A JFrame is a subclass of Frame class and the components added to a frame are referred to as its contents, these are managed by the contentPane. We can add the components to a JFrame to use its contentPane instead. A JFrame is like a Window with border, title, and buttons. We can implement most ... Read More

Advertisements