Raja has Published 760 Articles

How to implement custom FieldNamingStrategy using Gson in Java?

raja

raja

Updated on 07-Jul-2020 12:39:14

804 Views

The FieldNamingStrategy is a mechanism for providing custom field naming in Gson. This allows the client code to translate field names into a particular convention that is not supported as a normal Java field declaration rules. The translateName() method will prefix every field name with the string “pre_”.In the below example, ... Read More

How to get the JSONParser default settings using Jackson in Java?

raja

raja

Updated on 07-Jul-2020 12:18:20

299 Views

All the default settings of JSON Parser can be represented using the JsonParser.Feature enumeration. The JsonParser.Feature.values() will return all the features that are available for JSONParser but whether a feature is enabled or disabled for a particular parser can be determined using the isEnabled() method of JsonParser. Syntaxpublic static enum JsonParser.Feature extends EnumExampleimport com.fasterxml.jackson.core.*; import java.io.*; ... Read More

How to get the JsonFactory settings using Jackson in Java?

raja

raja

Updated on 07-Jul-2020 12:12:33

703 Views

The JsonFactory class is a thread-safe and responsible for creating instances of writer and reader. The list of settings that can be turned on/off is present in an enumeration JsonFactory.Feature, it contains static method values() that return the enum constant of this type with the specified name.Syntaxpublic static enum JsonFactory.Feature extends EnumExampleimport com.fasterxml.jackson.core.JsonFactory; ... Read More

How to get the JsonGenerator settings using Jackson in Java?

raja

raja

Updated on 07-Jul-2020 12:05:39

273 Views

The JsonGenerator class can be responsible for writing JSON data as a stream instead of constructing an Object Model in memory. The list of settings that can be turned on/off is present in an enum JsonGenerator.Feature, it contains static method values() that returns an array containing the constants of this enum type.Syntaxpublic static enum JsonGenerator.Feature ... Read More

FieldNamingPolicy enum using Gson in Java?

raja

raja

Updated on 07-Jul-2020 12:04:50

855 Views

Gson library provides the naming conventions as part of enum FieldNamingPolicy. We can set the field naming policy using the setFieldNamingPolicy() method of the GsonBuilder class.FieldNamingPolicy enum ConstantsIDENTITY − Using this naming policy, the field name is unchanged.LOWER_CASE_WITH_DASHES − Using this naming policy, modify the Java Field name from its camel-cased ... Read More

How to get the values of a key using the JsonPointer interface in Java?

raja

raja

Updated on 07-Jul-2020 11:58:26

581 Views

The JSONPointer is a standard that defines a string syntax that can be used to access a particular key value in the JSON document. An instance of JSONPointer can be created by calling the static factory method createPointer() on the Json class. In the JSONPointer,  every string syntax is prefixed with “/”. We can ... Read More

Importance of the JsonPatch interface in Java?

raja

raja

Updated on 07-Jul-2020 11:55:50

483 Views

The JsonPatch interface is a format for storing a sequence of operations that can be applied to the target JSON structure. There are few operations like add, remove, replace, copy, move and test can be stored in JsonPath and operated on JSON structure. The JsonPatchBuilder interface can be used for constructing a JSON patch ... Read More

How to create a JSON using JsonObjectBuilder and JsonArrayBuilder in Java?

raja

raja

Updated on 07-Jul-2020 11:43:40

7K+ Views

The JsonObjectBuilder can be used for creating JsonObject models whereas the JsonArrayBuilder can be used for creating JsonArray models. The JsonObjectBuilder can be created using the Json class, it contains methods to create the builder object and build an empty JsonObject instance using the Json.createObjectBuilder().build(). The JsonArrayBuilder can be created using the Json class, it contains methods to ... Read More

Pretty print JSON using javax.json API in Java?

raja

raja

Updated on 07-Jul-2020 07:58:47

710 Views

The javax.json package provides an Object Model API to process JSON. The Object Model API is a high-level API that provides immutable object models for JSON object and array structures. These JSON structures can be represented as object models using JsonObject and JsonArray interfaces. We can use the JsonGenerator interface to write the JSON data ... Read More

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

Advertisements