Raja has Published 760 Articles

How to rename the properties of JSON using Gson in Java?

raja

raja

Updated on 06-Jul-2020 13:17:10

3K+ Views

The Gson @SerializedName annotation can be serialized to a JSON with the provided name value as its field name. This annotation can override any FieldNamingPolicy including the default field naming policy that may have been set on the Gson instance. A different naming policy can set using the GsonBuilder class.Syntax@Retention(value=RUNTIME) @Target(value={FIELD, METHOD}) public ... Read More

When to use @JsonAutoDetect annotation in Java?

raja

raja

Updated on 06-Jul-2020 13:16:17

4K+ Views

The @JsonAutoDetect annotation can be used at the class level to override the visibility of the properties of a class during serialization and deserialization. We can set the visibility with the properties like "creatorVisibility", "fieldVisibility", "getterVisibility", "setterVisibility" and "isGetterVisibility". The JsonAutoDetect class can define public static constants that are similar to Java class visibility levels ... Read More

How to ignore a field of JSON object using the Jackson library in Java?

raja

raja

Updated on 06-Jul-2020 13:12:32

7K+ Views

The Jackson @JsonIgnore annotation can be used to ignore a certain property or field of a Java object. The property can be ignored both when reading JSON into Java objects and when writing Java objects into JSON. We can use the readValue() and writeValueAsString() methods of ObjectMapper class to read a JSON to ... Read More

How to serialize a JSON string to an Output Handler in Java?

raja

raja

Updated on 06-Jul-2020 13:11:16

509 Views

The Flexjson is a lightweight library for serializing and deserializing Java objects into and from JSON format. A JSONSerializer is the main class for performing serialization of Java objects to JSON. We can serialize a JSON string to an Output Handler using the WriterOutputHandler class and it implements the OutputHandler interface.Syntaxpublic class WriterOutputHandler extends Object implements ... Read More

Convert JSONObject to/from a cookie in Java?

raja

raja

Updated on 06-Jul-2020 13:05:15

1K+ Views

The JSON is one of the widely used data-interchange formats and is a lightweight and language independent. We can convert a JSONObject to cookie using the toString() method and convert a cookie to JSONObject using the toJSONObject() method of org.json.Cookie class.Convert JSONObject to cookieSyntaxpublic static java.lang.String toString(JSONObject jo) throws JSONExceptionExampleimport org.json.Cookie; import org.json.JSONObject; public ... Read More

How to auto-increment the property of a JSONObject in Java?

raja

raja

Updated on 06-Jul-2020 13:03:45

1K+ Views

A JSONObject is an unordered collection of name/value pairs and parses text from a String to produce a map-like object. However, we can auto-increment the property of a JSONObject using the increment() method of JSONObject class. If there is no such property, create one with a value of 1. If there is such a property ... Read More

How to wrap a JSON using flexjson in Java?

raja

raja

Updated on 06-Jul-2020 12:45:15

887 Views

The Flexjson library 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 wrap a JSON object using the rootName() method of JSONSerializer class, ... Read More

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

raja

raja

Updated on 06-Jul-2020 12:43:38

10K+ Views

The ObjectMapper class is the most important class in the Jackson API that provides readValue() and writeValue() methods to transform JSON to Java Object and Java Object to JSON. We can convert a List to JSON array using the writeValueAsString() method of ObjectMapper class and this method can be used to serialize ... Read More

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

raja

raja

Updated on 06-Jul-2020 12:42:31

3K+ Views

The JSON is one of the widely used data-interchange formats. It is a lightweight and language independent. A JSONArray can parse text from a String to produce a vector-like object and supports java.util.List interface.We can convert a JSONArray to String Array in the below exampleExampleimport org.json.*; import java.util.*; public class JsonArraytoStringArrayTest {    public static void ... Read More

How can we map multiple date formats using Jackson in Java?

raja

raja

Updated on 06-Jul-2020 12:33:55

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. We can map the multiple date formats in the Jackson library using @JsonFormat annotation, it is a general-purpose annotation used for configuring details of how values of properties are ... Read More

Advertisements