JSON Articles

Page 3 of 16

How to deserialize a JSON to Java object using the flexjson in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 12-May-2025 5K+ Views

Deserializing a JSON to a Java object means converting a JSON string into a Java object.The deserialize() Method of the Flexjson Library We will be using the Flexjson library to deserialize a JSON to a Java object in Java. The Flexjson library is a lightweight library that is used for serializing as well as deserializing Java objects to and from JSON. A JSONDeserializer is the main class for performing deserialization of JSON to Java objects. We can deserialize a JSON string to a Java object using the deserialize(String json, Class type) method of JSONDeserializer. Syntax of deserialize() Method The syntax of the ...

Read More

How to ignore the null and empty fields using the Jackson library in Java?\\n

Aishwarya Naglot
Aishwarya Naglot
Updated on 12-May-2025 2K+ Views

The Jackson is a library for Java and it has very powerful data binding capabilities and it also provides a framework to serialize custom java objects to JSON and deserialize JSON back to Java object. Ignoring Null and Empty Fields Using Jackson The Jackson library provides @JsonInclude annotation, which controls the serialization of a class as a whole or its individual fields based on their values during serialization. The @JsonInclude annotation contains below two values: Include.NON_NULL: Indicates that only properties with not null values will be included in JSON. Include.NON_EMPTY: Indicates ...

Read More

How can we change a field name in JSON using Jackson in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 12-May-2025 5K+ Views

When we have a JSON object and want to change a specific field name for some reason, we can use the Jackson library in Java.The Jackson Annotation @JsonProperty The Jackson Annotation @JsonProperty is used on a property or method during the serialization or deserialization of JSON. It takes an optional 'name' parameter, which is useful in case the property name is different from the key name in JSON. By default, if the key name matches the property name, the value is mapped to the property value. If the key name is different, we can use the @JsonProperty annotation to ...

Read More

How to exclude a field from JSON using @Expose annotation in Java?

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

Sometimes we need to exclude certain fields from the JSON output. For example, if we have a field that contains sensitive information, we may not want to include it in the JSON representation of the object. In such cases, we can use the Expose annotation provided by Gson. The Gson @Expose annotation The Gson @Expose annotation can be used to specify whether a field isto be exposed or not (included or not). The @Expose annotation can take two parameters, and each parameter is a boolean which can take either the value true or false. The two parameters are: ...

Read More

Pretty print JSON using Jackson library in Java?

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

A Jackson API is a Java-based library, and it can be useful to convert 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 process a JSON in three different ways: Streaming API, Tree Model, and Data Binding. We can pretty print JSON using the writerWithDefaultPrettyPrinter() of the ObjectMapper class, which is a factory method for constructing an ObjectWriter that will serialize objects using the default pretty printer for indentation. In this article, we will learn how to pretty print JSON using the Jackson ...

Read More

Convert JSON to/from Map using Jackson library in Java?

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

JSON is a format that is used to exchange data between a server and a client. It is lightweight and easy to read and write. In Java, we can convert JSON to/from Map using various libraries. In this article, we will discuss how to convert JSON to/from Map using the Jackson library. The Jackson is a library for Java, and it has very powerful data binding capabilities and provides a framework to serialize custom java objects to JSON and deserialize JSON back to Java object. We can convert JSON to/from Map using readValue() and writeValueAsString() methods of com.fasterxml.jackson.databind.ObjectMapper class. To ...

Read More

How to format a date using the Gson library in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 12-May-2025 7K+ Views

Gson is a JSON for Java, which is developed by Google. We can format a date using the Gson library in Java. The Gson library provides a GsonBuilder class that allows us to create a Gson instance with custom settings. We call the create() method of the GsonBuilder class to create an instance of the Gson class. Then we use the method setDateFormat() to configure Gson to serialize Date objects according to the pattern provided. In order to use the Gson library, we need to add it to our project. If you are using Maven, add this to your ...

Read More

Importance of a JSONTokener in Java?\\n

Aishwarya Naglot
Aishwarya Naglot
Updated on 12-May-2025 2K+ Views

If you have ever worked with JSON in Java, you might have used classes like JSONObject, JSONArray, JsonParser, etc. These classes are part of the org.json library. We use these classes to build JSON or parse JSON. But behind the scenes, these classes use a class called JSONTokener. In this article, we will learn about the JSONTokener class and its importance in Java. What is JSONTokener? The JSONTokener class is like a tool that reads a JSON string step by step, breaking it into smaller parts called tokens. It is like a helper that makes it easier to understand and ...

Read More

How to implement custom JSON de-serialization with Gson in Java?\\n

Aishwarya Naglot
Aishwarya Naglot
Updated on 12-May-2025 763 Views

Deserialization is the process of converting JSON data back into Java objects. Gson provides a simple way to do this using the fromJson() method. Custom JSON de-serialization with Gson Gson is a Java library developed by Google to convert Java objects into their JSON format and vice versa. Custom JSON is a way we can modify or extend the standard JSON format so that it can suit our specific needs. To use the Gson library, we need to add the Gson library to our project. If you are using Maven, add this to your pom.xml file: com.google.code.gson gson 2.8.9 ...

Read More

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

Manisha Chand
Manisha Chand
Updated on 29-Apr-2025 12K+ Views

JSON is used in Java applications in APIs, file storage, and data communication between systems. Sometimes, we need to convert a list into a JSON array. In this article, we will learn how to convert a list to JSON array using the Jackson library. Jackson Library It is a library that is used in Java to work with JSON data. It provides APIs to serialize Java objects into JSON and deserialize JSON back into Java objects. If you want to read more about the Jackson library, you can refer Jackson library. There are mainly three components of Jackson - ...

Read More
Showing 21–30 of 152 articles
« Prev 1 2 3 4 5 16 Next »
Advertisements