Raja has Published 469 Articles

How can we use lambda expressions with functional interfaces in Java?

raja

raja

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

814 Views

The lambda expressions are anonymous functions and don't have any return type, access modifier and not belonging to any class. It can be used to simplify the implementation of the abstract method in a functional interface. Whenever there is a functional interface, we can use lambda expressions instead of anonymous inner classes.Syntax([comma ... Read More

What to use @SerializedName annotation using Gson in Java?

raja

raja

Updated on 09-Jul-2020 08:17:53

8K+ Views

The @SerializedName annotation can be used to serialize a field with a different name instead of an actual field name. We can provide the expected serialized name as an annotation attribute, Gson can make sure to read or write a field with the provided name.Syntax@Retention(value=RUNTIME) @Target(value={FIELD, METHOD}) public @interface SerializedNameExampleimport ... Read More

How to implement custom JsonAdapter using Gson in Java?

raja

raja

Updated on 09-Jul-2020 08:15:08

3K+ Views

The @JsonAdapter annotation can be used at field or class level to specify the Gson. The TypeAdapter class can be used to convert Java objects to and from JSON. By default, Gson library converts application classes to JSON by using built-in type adapters but we can override it by providing custom ... Read More

How to convert JsonNode to ArrayNode using Jackson API in Java?

raja

raja

Updated on 09-Jul-2020 07:59:35

18K+ Views

A JsonNode is a base class for all JSON nodes that forms the JSON Tree Model whereas ArrayNode is a node class that represents an array mapped from JSON content. We can convert or translate JsonNode to ArrayNode by typecasting the ArrayNode to retrieve the values using the readTree() method of ObjectMapper class ... Read More

How to search a value inside a JSON file using Jackson in Java?

raja

raja

Updated on 09-Jul-2020 07:52:12

3K+ Views

The com.fasterxml.jackson.databind.node.ObjectNode class can be used to map the JSON object structure in Json content. We can search for a particular value inside the JSON file using the get() method of ObjectNode class, this method used for accessing the value of a specified field of an object node.Syntaxpublic JsonNode get(String fieldName)Exampleimport ... Read More

Importance of @JsonUnwrapped annotation using Jackson in Java?

raja

raja

Updated on 09-Jul-2020 06:43:52

963 Views

The @JsonUnwrapped annotation can be used to unwrap values during the serialization and deserialization process. It helps to render the values of a composed class as if it belongs to the parent class.Syntax@Target(value={ANNOTATION_TYPE, FIELD, METHOD, PARAMETER}) @Retention(value=RUNTIME) public @interface JsonUnwrappedExampleimport com.fasterxml.jackson.annotation.JsonUnwrapped; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.core.JsonProcessingException; public class JsonUnwrappedAnnotationTest {   ... Read More

How to implement custom deserializer using @JsonDeserialize annotation in Java?

raja

raja

Updated on 09-Jul-2020 06:19:40

3K+ Views

The @JsonDeserialize annotation is used to declare custom deserializer while deserializing JSON to Java object. We can implement a  custom deserializer by extending the StdDeserializer class with a generic type Employee and need to override the deserialize() method of StdDeserializer class.Syntax@Target(value={ANNOTATION_TYPE, METHOD, FIELD, TYPE, PARAMETER}) @Retention(value=RUNTIME) public @interface JsonDeserializeIn the below program, we ... Read More

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

raja

raja

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

290 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

Advertisements