Raja has Published 469 Articles

When to use @JsonAutoDetect annotation in Java?

raja

raja

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

5K+ 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

9K+ 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

623 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

1K+ 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 can we serialize a list of objects using flexjson in Java?

raja

raja

Updated on 06-Jul-2020 12:26:47

1K+ Views

The Flexjson is a lightweight library for serializing and deserializing Java objects into and from JSON format. We can serialize a list of objects using the serialize() method of JSONSerializer class. This method can perform a shallow serialization of the target instance. We need to pass a list of objects of List type as an argument to the serialize() method.Syntaxpublic String serialize(Object ... Read More

When can we call @JsonAnyGetter and @JsonAnySetter annotations in Java?

raja

raja

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

2K+ Views

The @JsonAnyGetter annotation enables to use a Map as a container for properties that we want to serialize to JSON and @JsonAnySetter annotation instructs Jackson to call the same setter method for all unrecognized fields in the JSON object, which means that all fields that are not already mapped to a property or setter ... Read More

How to implement a custom serializer using the Jackson library in Java?

raja

raja

Updated on 06-Jul-2020 11:52:25

1K+ Views

The Jackson API provides a number of methods to work with JSON data. By using Jackson API, we can convert Java objects to JSON string and reform the object from the JSON string. We can implement a custom serializer using the StdSerializer class and need to override the serialize(T value, JsonGenerator gen, SerializerProvider ... Read More

Convert CSV to JSON using the Jackson library in Java?

raja

raja

Updated on 06-Jul-2020 11:44:03

8K+ Views

A Jackson is a Java JSON API that provides several different ways to work with JSON. We can convert CSV data to JSON data using the CsvMapper class, it is specialized ObjectMapper, with extended functionality to produce CsvSchema instances out of POJOs. We can use the reader() method for constructing ObjectReader with default settings. In order ... Read More

Advertisements