Raja has Published 760 Articles

How to control serialization through @JSON annotation using flexjson in Java?

raja

raja

Updated on 09-Jul-2020 06:17:06

206 Views

The @JSON annotation is used by JSONSerializer class to exclude or include a field during the serialization process. We can use the serialize() method of JSONSerializer class to perform a shallow serialization of the target instance.Syntax@Retention(value=RUNTIME) @Target(value={FIELD, TYPE, METHOD}) public @interface JSONExampleimport flexjson.JSONSerializer; import flexjson.JSON; public class JSONAnnotationTest {    public static void ... Read More

How to implement custom serializer using @JsonSerialize annotation in Java?

raja

raja

Updated on 09-Jul-2020 05:49:14

2K+ Views

The @JsonSerialize annotation is used to declare custom serializer during the serialization of a field. We can implement a custom serializer by extending the StdSeralizer class. and need to override the serialize() method of StdSerializer class.Syntax@Target(value={ANNOTATION_TYPE, METHOD, FIELD, TYPE, PARAMETER}) @Retention(value=RUNTIME) public @interface JsonSerializeIn the below program, we can implement a ... Read More

How to convert a JSON string to a bean using JSON-lib API in Java?

raja

raja

Updated on 09-Jul-2020 05:18:38

1K+ Views

The JSON-lib API is a java library to serialize and de-serialize java beans, maps, arrays, and collections in the JSON format. We need to convert a JSON string to a bean by converting a string to JSON object first then convert this to a java bean.Syntaxpublic static Object toBean(JSONObject jsonObject, Class beanClass)In ... Read More

Importance of @JsonIdentityInfo annotation using Jackson in Java?

raja

raja

Updated on 09-Jul-2020 05:13:16

1K+ Views

The @JsonIdentityInfo annotation is used when an object has a parent-child relationship in the Jackson library. The @JsonIdentityInfo annotation is used to indicate the object identity during the serialization and deserialization process. The ObjectIdGenerators.PropertyGenerator is an abstract place-holder class to denote a case where Object Identifier to use comes from a POJO property.Syntax@Target(value={ANNOTATION_TYPE, TYPE, ... Read More

How to convert a JSON array to array using JSON-lib API in Java?

raja

raja

Updated on 08-Jul-2020 12:53:38

1K+ Views

The JSONArray is a sequence of values, the external text is a string enclosed in square brackets with commas separating the values and internal text is an object having get() and opt() methods, we need to access those values by index. The element() method for adding or replacing those values. An array is ... Read More

How can we use @Since annotation using Gson in Java?

raja

raja

Updated on 08-Jul-2020 12:38:47

277 Views

The @Since annotation can use with the setVersion() method of the GsonBuilder class. This annotation can apply to a field in java class and accepts float as an argument. This argument represents the version number in which the field has serialized. The same can apply to the deserialization process.Syntax@Documented @Retention(value=RUNTIME) @Target(value={FIELD, ... Read More

How to use @Until annotation using the Gson library in Java?

raja

raja

Updated on 08-Jul-2020 12:01:11

227 Views

The @Until annotation can use with the setVersion() method of the GsonBuilder class. This annotation can apply to a field in java class and accepts float as an argument. This argument represents the version number in which the field has serialized. The @Until annotation can manage the versioning of JSON classes in ... Read More

Importance of @JsonRootName annotation using Jackson in Java?

raja

raja

Updated on 08-Jul-2020 11:40:50

911 Views

The @JsonRootName annotation can be used to wrap an object to serialize with a top-level element. We can pass the name as a parameter to @JsonRootName annotation. We can use the "WRAP_ROOT_VALUE" feature of SerializationFeature enum that can be enabled to make root value wrapped within a single property JSON object where the key ... Read More

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

raja

raja

Updated on 08-Jul-2020 11:38:24

1K+ Views

The @JsonRawValue annotation can be used for both methods and fields to serialize field or property as declared. For instance, if we have a String field in our Java class, the JSON value is enclosed within quotes (“ "). But when we annotate the field with @JsonRawValue annotation, Jackson library ... Read More

When to use @JsonManagedReference and @JsonBackReference annotations using Jackson in Java?

raja

raja

Updated on 08-Jul-2020 11:36:22

4K+ Views

The @JsonManagedReference and @JsonBackReference annotations can be used to create a JSON structure in a bidirectional way. The @JsonManagedReference annotation is a forward reference that includes during the serialization process whereas @JsonBackReference annotation is a backreference that omits during the serialization process.In the below example, we can implement @JsonManagedReference and @JsonBackReference annotations.Exampleimport java.util.*; import ... Read More

Advertisements