Raja has Published 760 Articles

How many parameters can a lambda expression have in Java?

raja

raja

Updated on 10-Jul-2020 08:32:24

3K+ Views

The lambda expressions are easy and contain three parts like parameters (method arguments), arrow operator (->) and expressions (method body). The lambda expressions can be categorized into three types: no parameter lambda expressions, single parameter lambda expressions and multiple parameters lambda expressions.Lambda Expression with no parameterWe need to create no parameter lambda expression then ... Read More

What are block lambda expressions in Java?

raja

raja

Updated on 10-Jul-2020 06:43:27

803 Views

A lambda block states that lambda expression with multiple statements. It expands the type of operations to perform with a lambda expression. The multiple statements containing bodies are called expression bodies. A lambda expression with expression bodies is called expression lambdas. Whenever we are using expression lambdas, explicitly use a return ... Read More

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

raja

raja

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

638 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

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

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

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

When to use @ConstructorProperties annotation with Jackson in Java?

raja

raja

Updated on 09-Jul-2020 07:19:56

1K+ Views

The @ConstructorProperties annotation is from java.beans package, used to deserialize JSON to java object via the annotated constructor. This annotation supports from Jackson 2.7 version onwards. The way this annotation works very simple, rather than annotating each parameter in the constructor, we can provide an array with the properties names for ... Read More

Importance of @JsonUnwrapped annotation using Jackson in Java?

raja

raja

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

457 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

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

Advertisements