Raja has Published 760 Articles

How to create a JSON Object using Object Model in Java?

raja

raja

Updated on 07-Jul-2020 07:25:17

2K+ Views

The javax.json.JsonObject interface can represent an immutable JSON object value and provides an unmodifiable map view to the JSON object name/value mappings. A JsonObject instance can be created from an input source using the static method readObject() of javax.json.JsonReader class and also can be created using the static method createObjectBuilder() of javax.json.Json class.Syntaxpublic static JsonObjectBuilder createObjectBuilder()Exampleimport java.io.*; import ... Read More

How to create a JSON Array using Object Model in Java?

raja

raja

Updated on 07-Jul-2020 07:09:51

1K+ Views

The javax.json.JsonArray interface can represent an immutable JSON array and provides an unmodifiable list view of the values in the array. A JsonArray object can be created by reading JSON data from an input source and also using a static method createArrayBuilder() of javax.json.Json class. We need to import the javax.json package (download javax.json-api.jar file) in ... Read More

How to deserialize a Java object from Reader Stream using flexjson in Java?

raja

raja

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

280 Views

The Flexjson is a lightweight library for serializing and deserializing Java objects into and from JSON format. We can deserialize a Java object from a Reader stream using the deserialize() method of JSONDeserializer class, it uses an instance of Reader class as JSON input.Syntaxpublic T deserialize(Reader input)Exampleimport java.io.*; import flexjson.JSONDeserializer; public class JSONDeserializeReaderTest { ... Read More

Importance of the accumulate() method of JSONObject in Java?

raja

raja

Updated on 07-Jul-2020 05:54:35

1K+ Views

A JSONObject is an unordered collection of a name and value pairs. A few important methods of JSONArray are accumulate(), put(), opt(), append(), write() and etc. The accumulate() method accumulates the values under a key and this method similar to the put() method except if there is an existing object stored under a key ... Read More

How to convert a JSON object to an enum using Jackson in Java?

raja

raja

Updated on 07-Jul-2020 05:29:47

4K+ Views

A JSONObject can parse the text from String to produce a Map kind of an object. An Enum can be used to define a collection of constants, when we need a predefined list of values which do not represent some kind of numeric or textual data then we can use an enum. We ... Read More

Importance of the Jackson @JsonInclude annotation in Java?

raja

raja

Updated on 07-Jul-2020 05:25:26

1K+ Views

The Jackson @JsonInclude annotation can be used to exclude the properties or fields of a class under certain conditions and it can be defined using the JsonInclude.Include enum. The JsonInclude.Include enum contains few constants like "ALWAYS", "NON_DEFAULT", "NON_EMPTY" and "NON_NULL" to determine whether to exclude the property(field) or not.Syntaxpublic static enum JsonInclude.Include extends EnumExampleimport com.fasterxml.jackson.annotation.*; ... Read More

What is the use of @JacksonInject annotation using Jackson in Java?

raja

raja

Updated on 06-Jul-2020 13:35:24

449 Views

The Jackson @JacksonInject annotation can be used to inject the values into parsed objects instead of reading those values from the JSON. In order to inject values into a field, we can use the InjectableValues class and need to configure the ObjectMapper class to read both the injected values from the InjectableValues class ... Read More

How to ignore a class during the serialization using Jackson in Java?

raja

raja

Updated on 06-Jul-2020 13:29:57

2K+ Views

The Jackson @JsonIgnoreType annotation can be used to ignore a class during the serialization process and it can mark all the properties or fields of a class to be ignored while serializing and deserializing a JSON object.Syntax@Target(value={ANNOTATION_TYPE, TYPE}) @Retention(value=RUNTIME) public @interface JsonIgnoreTypeExampleimport com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.databind.*; import java.io.*; public class JsonIgnoreTypeTest {    public static void ... Read More

How to add a JSON string to an existing JSON file in Java?

raja

raja

Updated on 06-Jul-2020 13:21:04

5K+ Views

A Gson is a json library for Java and it can be used to generate a JSON. In the initial step, we can read a JSON file and parsing to a Java object then need to typecast the Java object to a JSonObject and parsing to a JsonArray. Then iterating this JSON array ... Read More

How to ignore the multiple properties of a JSON object in Java?

raja

raja

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

3K+ Views

The @JsonIgnoreProperties Jackson annotation can be used to specify a list of properties or fields of a class to ignore. The @JsonIgnoreProperties annotation can be placed above the class declaration instead of above the individual properties or fields to ignore.Syntax@Target(value={ANNOTATION_TYPE, TYPE, METHOD, CONSTRUCTOR, FIELD}) @Retention(value=RUNTIME) public @interface JsonIgnorePropertiesExampleimport java.io.*; import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.*; public ... Read More

Advertisements