Raja has Published 469 Articles

How to parse a JSON string using Streaming API in Java?

raja

raja

Updated on 07-Jul-2020 07:40:21

2K+ Views

The Streaming API consists of an important interface JsonParser and this interface contains methods to parse JSON in a streaming way and provides forward, read-only access to JSON data. The Json class contains the methods to create parsers from input sources. We can parse a JSON using the static method createParser() of Json class.Syntaxpublic static JsonParser ... Read More

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

raja

raja

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

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

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

394 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

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

raja

raja

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

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

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

638 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 add a JSON string to an existing JSON file in Java?

raja

raja

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

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

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

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

raja

raja

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

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

Advertisements