Raja has Published 760 Articles

Convert POJO to XML using the Jackson library in Java?

raja

raja

Updated on 06-Jul-2020 09:24:08

5K+ Views

A Jackson is a Java-based library and it can be useful to convert Java objects to JSON and JSON to Java Object. A Jackson API is faster than other API, needs less memory area and is good for the large objects. We convert a POJO to XML format using the writeValueAsString() ... Read More

How to parse a JSON without duplicate keys using Gson in Java?

raja

raja

Updated on 06-Jul-2020 08:51:36

917 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. We can parse a JSON without duplicate keys using ... Read More

How can we format a date using the Jackson library in Java?

raja

raja

Updated on 06-Jul-2020 08:47:42

2K+ Views

A Jackson is a Java based library and it can be useful to convert Java objects to JSON and JSON to Java Object. A Jackson API is faster than other API, needs less memory area and is good for the large objects. We can format a date using the setDateFormat() of ... Read More

How to serialize a map using the flexjson library in Java?

raja

raja

Updated on 06-Jul-2020 08:23:21

239 Views

The Flexjson is a lightweight library for serializing and deserializing Java objects into and from JSON format. We can also serialize a Map using the serialize() method of JSONSerializer class, it performs a shallow serialization of the target instance.Syntaxpublic String serialize(Object target)Exampleimport flexjson.JSONSerializer; import java.util.*; public class JsonSerializeMapTest {    public static void ... Read More

Differences between fromJson() and toJson() methods of Gson in Java?

raja

raja

Updated on 06-Jul-2020 07:38:10

4K+ Views

A Gson is a library for java and it can be used to generate a JSON. We can use the fromJson() method of Gson to parse JSON string into java object and use the toJson() method of Gson to convert Java objects into JSON string. There are two parameters in the fromJson() method, the ... Read More

How to exclude a field in Gson during serialization in Java?

raja

raja

Updated on 06-Jul-2020 07:36:24

499 Views

The Gson library provided a simple approach to exclude fields from serialization using a transient modifier. If we make a field in a Java class as transient then Gson can ignore for both serialization and deserialization.Exampleimport com.google.gson.*; public class GsonTransientFieldTest {    public static void main(String[] args) {       Gson gson = ... Read More

How can we serialize an array of objects using flexjson in Java?

raja

raja

Updated on 06-Jul-2020 07:08:44

349 Views

The Flexjson is a lightweight library for serializing and deserializing Java objects into and from JSON format. We can also serialize an array of objects using the serialize() method of JSONSerializer class, this performs a shallow serialization of the target instance.Syntaxpublic String serialize(Object target)In the below program, we need to serialize an array of objects.Exampleimport flexjson.JSONSerializer; public ... Read More

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

raja

raja

Updated on 06-Jul-2020 07:04:40

3K+ Views

The Flexjson is a lightweight java library for serializing and deserializing java beans, maps, arrays, and collections in JSON format. We can also deserialize a JSON string to an existing object using the deserializeInto() method of JSONDeserializer class, this method deserializes the given input into the existing object target. The values in the json input can ... Read More

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

raja

raja

Updated on 06-Jul-2020 06:52:49

2K+ Views

The Gson @Expose annotation can be used to mark a field to be exposed or not (included or not) for serialized or deserialized. The @Expose annotation can take two parameters and each parameter is a boolean which can take either the value true or false. In order to get GSON to ... Read More

How can we read & write a file using Gson streaming API in Java?

raja

raja

Updated on 06-Jul-2020 06:24:19

847 Views

We can read and write a file using Gson streaming API and it is based on sequential read and write standard. The JsonWriter and JsonReader are the core classes built for streaming write and read in Streaming API. The JsonWriter writes a JSON encoded value to a stream, one token at a time. The ... Read More

Advertisements