Raja has Published 760 Articles

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

raja

raja

Updated on 06-Jul-2020 06:06:00

4K+ Views

The Jackson Annotation @JsonProperty is used on a property or method during serialization or deserialization of JSON. It takes an optional ‘name’ parameter which is useful in case the property name is different than ‘key’ name in JSON. By default, if the key name matches the property name, value is mapped to property value.In ... Read More

How to parse a JSON to Gson Tree Model in Java?

raja

raja

Updated on 06-Jul-2020 06:04:59

2K+ Views

The Gson library can be used to parse a JSON String into a Tree Model. We can use the JsonParser to parse the JSON string into a Tree Model of type JsonElement. The getAsJsonObject() method of JsonElement can be used to get the element as JsonObject and getAsJsonArray() method of JsonElement can be used to get the element ... Read More

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

raja

raja

Updated on 06-Jul-2020 05:57:50

1K+ Views

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. The Jackson library provides @JsonInclude annotation that controls the serialization of a class as a whole or its ... Read More

Pretty print JSON using the flexjson library in Java?

raja

raja

Updated on 06-Jul-2020 05:53:33

232 Views

The Flexjson is a lightweight Java library for serializing and de-serializing java beans, maps, arrays, and collections in a JSON format. A JSONSerializer is the main class for performing serialization of Java objects to JSON and by default performs a shallow serialization. We can pretty-print JSON using the prettyPrint(boolean prettyPrint) method of JSONSerializer class.Syntaxpublic JSONSerializer prettyPrint(boolean prettyPrint)In ... Read More

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

raja

raja

Updated on 04-Jul-2020 13:01:23

4K+ Views

The Flexjson is a lightweight library for serializing and deserializing Java objects into and from JSON format allowing both deep and shallow copies of objects. In order to run a Java program with flexjon, we need to import a flexjson package. We can deserialize a JSON to Java object using the deserialize() method of JSONDeserializer class, ... Read More

Custom instance creator using Gson in Java?

raja

raja

Updated on 04-Jul-2020 12:48:43

2K+ Views

While parsing JSON String to or from Java object, By default Gson try to create an instance of Java class by calling the default constructor. In the case of Java class doesn’t contain default constructor or we want to do some initial configuration while creating Java objects, we need to ... Read More

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

raja

raja

Updated on 04-Jul-2020 12:34:19

6K+ Views

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. 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 ... Read More

How to configure Gson to enable versioning support in Java?

raja

raja

Updated on 04-Jul-2020 12:20:30

103 Views

The Gson library provides a simple versioning system for the Java objects that it reads and writes and also provides an annotation named @Since for the versioning concept @Since(versionnumber).We can create a Gson instance with versioning using the GsonBuilder().setVersion() method. If we mentioned like setVersion(2.0),  means that all the fields having 2.0 or less ... Read More

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

raja

raja

Updated on 04-Jul-2020 12:13:14

5K+ Views

A Gson is a JSON library for Java, which is created by Google. By using Gson, we can generate JSON and convert JSON to java objects. We can create a Gson instance by creating a GsonBuilder instance and calling with the create() method. The GsonBuilder().setDateFormat() method configures Gson to serialize Date objects according to the ... Read More

Pretty print JSON using org.json library in Java?

raja

raja

Updated on 04-Jul-2020 11:44:53

9K+ Views

The JSON is a lightweight, text-based and language-independent data exchange format. A.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 files in the org.json package implement JSON encoders/decoders in Java. It also includes the capability to ... Read More

Advertisements