JSON Articles

Page 5 of 16

Convert POJO to XML using the Jackson library in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 01-Sep-2025 7K+ Views

Jackson is a library that allows you to convert Java objects into XML and vice versa. In this example, we will demonstrate how to convert a POJO (Plain Old Java Object) into XML using the Jackson library. Well, if you are not familiar with POJO, it is a simple Java object that does not follow any specific framework or design pattern. It is just a regular Java class with fields and methods. We will use the method writeValueAsString() of the XmlMapper class to convert a POJO into XML. The XmlMapper class is part of the Jackson library and it ...

Read More

How can we ignore the fields during JSON serialization in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 01-Sep-2025 14K+ Views

If there are fields in Java objects that do not wish to be serialized, we can use the @JsonIgnore annotation in the Jackson library. The @JsonIgnore can be used at the field level, for ignoring fields during the serialization and deserialization. In this article, we will learn how to ignore the fields during JSON serialization in Java using the Jackson library. Steps to ignore the fields during JSON serialization in Java: In order to use Jackson, you will need to add it to your project. If you use Maven, add the following dependency to your ...

Read More

How can we convert a JSONArray to String Array in Java?

Manisha Chand
Manisha Chand
Updated on 06-Jun-2025 4K+ Views

A JSONArray is a class provided by the org.json package that represents a collection of JSON values. These values can be of any type, such as strings, numbers, booleans, or even nested objects or arrays. If you do not know what JSON is, then you can read the JSON tutorial. Converting JSON Array to String ArrayWe can convert a JSONArray to String Array by using a simple loop as shown in the example below - import org.json.*; import java.util.*; public class JsonArraytoStringArrayTest { public static void main(String[] args) { ...

Read More

How can we convert a JSON array to a list using Jackson in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 05-Jun-2025 9K+ Views

Jackson is a Java-based library, and it can be useful for converting Java objects to JSON and JSON to Java objects. A Jackson API is faster than other API, needs less memory, and is good for large objects. We can convert a JSON array to a list using the ObjectMapper class. It has a useful method,  readValue(), which takes a JSON string and converts it to the object class specified in the second argument. Before proceeding further, first of all, we need to import the Jackson library into our project. To do this, you can add the following dependency to ...

Read More

Differences between org.simple.json and org.json libraries in Java?

Manisha Chand
Manisha Chand
Updated on 20-May-2025 3K+ Views

In Java, org.simple.json and org.json are two libraries that help in reading, writing, and manipulating JSON. But still, they are different. In this article, we are going to learn about these differences. Difference between JSON.simple vs JSON Let's see the below differences and they are - Features JSON.simple JSON ...

Read More

When to use @JsonValue annotation using Jackson in Java?

Manisha Chand
Manisha Chand
Updated on 19-May-2025 6K+ Views

In Java, Jackson is a library that is used to convert JSON to Java objects and vice versa. Jackson Annotations are used during serialization and deserialization. We use these to denote or specify annotations before a particular field or method (that is declared in Java). Using an annotation before a field, we can denote whether it is a variable, is a JsonProperty, should be ignored, or what condition should be applied to it. So basically, Annotations make JSON output clearer as we required. In this Article, we will learn about ...

Read More

How to convert a JSON to Java Object using the Jackson library in Java?

Manisha Chand
Manisha Chand
Updated on 19-May-2025 42K+ Views

Jackson is a Java library that is used to convert JSON to Java objects and vice versa. Conversion of JSON to a Java object is called deserialization, and Java object to JSON is known as serialization. Both of these tasks can be done by using the Jackson library. In this article, we are going to learn how to convert JSON to Java objects using the Jackson library. Jackson Library: Convert a JSON to a Java Object The ObjectMapper class belongs to the Jackson library. This class is responsible for the serialization and deserialization of Java objects. The ObjectMapper class is used ...

Read More

How to access the JSON fields, arrays and nested objects of JsonNode in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 13-May-2025 34K+ Views

What are JSON and JsonNode? JSON is a format that is used to store data and exchange data between a server and a client. To know more about JSON, you can refer to the JSON Tutorial. A JsonNode is Jackson's tree model for JSON. To read JSON into a JsonNode with Jackson by creating an ObjectMapper instance and call the readValue() method. We can access a field, array or nested object using the get() method of the JsonNode class. We can return a valid string representation using the asText() method and ...

Read More

How to serialize a null field using Gson library in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 13-May-2025 8K+ Views

Gson is a library in the Java that is mainly used for converting Java objects to JSON and vice versa. By default, the Gson object does not serialize the fields with null values to JSON. If a field in a Java object is null, Gson excludes it.Serializing a Null Field Using Gson We can force Gson to serialize null values via the GsonBuilder class. We need to call the serializeNulls() method on the GsonBuilder instance before creating the Gson object. Once serializeNulls() has been called, the Gson instance created by the GsonBuilder can include null fields in the serialized JSON. ...

Read More

How to deserialize a JSON into an existing object in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 13-May-2025 3K+ Views

Deserialization is the process of converting a JSON string into a Java object. In this example, we will learn how to deserialize a JSON string into an existing object in Java. There are libraries available in Java that can help us to deserialize a JSON string into an existing object. Some of the popular libraries are: Using Gson Using Jackson Using Flexjson Let's learn how to use each of these libraries to deserialize a JSON string into an existing object in Java. Deserializing JSON Object Using ...

Read More
Showing 41–50 of 152 articles
« Prev 1 3 4 5 6 7 16 Next »
Advertisements