In this post under MapStruct, I will show with example how to map hierarchical objects properties to flat object. In all my previous posts under MapStruct, the source object didn’t compose another object. In other words, there was no object hierarchy. In this post I will use a source object which has a hierarchy as…… Continue reading Mapping hierarchical objects to flat objects
Accessing list in SpEL
In this post under Spring SpEL, I will show with example how to access list in SpEL. For our example I will create the below main class Main class 1 package spel.package4; 2 3 import org.springframework.beans.factory.annotation.Value; 4 import org.springframework.context.ApplicationContext; 5 import org.springframework.context.annotation.AnnotationConfigApplicationContext; 6 import org.springframework.context.annotation.Bean; 7 import org.springframework.context.annotation.ComponentScan; 8 import org.springframework.stereotype.Component; 9 10 import java.util.ArrayList;…… Continue reading Accessing list in SpEL
Accessing map in SpEL
In this post under Spring SpEL, I will show with example how to access map in SpEL. For our example I will create the below main class Main class 1 package spel.package3; 2 3 import org.springframework.beans.factory.annotation.Value; 4 import org.springframework.context.ApplicationContext; 5 import org.springframework.context.annotation.AnnotationConfigApplicationContext; 6 import org.springframework.context.annotation.Bean; 7 import org.springframework.context.annotation.ComponentScan; 8 import org.springframework.context.annotation.Configuration; 9 10 import java.util.HashMap;…… Continue reading Accessing map in SpEL
Converting Array to Stream
In this post under Java Collections, I will show with example how to convert an existing array to Stream. For this purpose, Java provides static method named “stream” in Arrays class. This method takes an array as an input and convert it into a stream. Below is the complete main code for your reference Main…… Continue reading Converting Array to Stream
Arrays copyOfRange method example
In this post under Java collections, I will show with example the purpose of “Arrays” class “copyOfRange” method. In the previous post under Java collections, I showed with example the purpose of “Arrays” class “copyOf” method. This method copies all the elements of input array to destination array. But what if we want to copy…… Continue reading Arrays copyOfRange method example
Generating random password using only user defined characters
In this post under Passay, I will show with example how to generate random password using user defined characters. To generate a random password, we need to come up with a list of “CharacterRule” instances. Each “CharacterRule” class take two data as constructor arguments as listed below1) instance of “CharacterData” interface2) min number of characters…… Continue reading Generating random password using only user defined characters
Mapping a map to a bean
In this post under MapStruct, I will show with example how to map values of Map to a bean. In our example we use map a Map to “StudentDTO” object. Below is the class structure of “StudentDTO” class. StudentDTO package package7; public class StudentDTO { private Integer id; private String name; private String className; //Removed…… Continue reading Mapping a map to a bean
Marshalling and Unmarshalling a generic object
In this post under Jackson –> JSON, I will explain with example how to marshal and unmarshal a generic object. Below is the complete main code for your reference Main class 1 package package14; 2 3 import com.fasterxml.jackson.core.type.TypeReference; 4 import com.fasterxml.jackson.databind.ObjectMapper; 5 6 import java.util.ArrayList; 7 import java.util.List; 8 9 public class Example14 { 10…… Continue reading Marshalling and Unmarshalling a generic object
Arrays.copyOf method
In this post under Java Collections, I will explain with example the purpose and how to use “Arrays” class public static method “copyOf”. Arrays.copyOf method takes a source array, creates a destination array, and copies the elements present in source array to destination array. Lets see an eample. Below is the main class Main class…… Continue reading Arrays.copyOf method
Mapping to existing bean instances
In this post under MapStruct, I will explain with example how to map attributes from source object to attributes of another existing object. In all my previous post under MapStruct, when mapping attributes from source object to destination object, the Mapper framework used to create the destination object before mapping. But there may be scenarios…… Continue reading Mapping to existing bean instances