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
Checking whether the password is already present in another source
In this post under Passay, I will show how to check whether the password is already used in another source. Below is the complete main class for your reference. Main class 1 package defaultPackage; 2 3 import java.util.ArrayList; 4 import java.util.List; 5 6 import org.passay.PasswordData; 7 import org.passay.PasswordData.SourceReference; 8 import org.passay.PasswordValidator; 9 import org.passay.RuleResult; 10…… Continue reading Checking whether the password is already present in another source
Accessing array in SpEL
In this post under Spring SpEL, I will show how to access array elements in SpEL expressions. For our example I will use the two beans. Below is the class structure of them Bean1 class package spel.package2; import org.springframework.stereotype.Component; @Component public class Bean1 { private int[] values = new int[] {1, 2, 3, 4}; public…… Continue reading Accessing array in SpEL
SpEL Simple example
In this post under Spring SpEL, I will give a simple example that shows how to access bean properties and use literal values in SpEL expressions. SpEL (Spring Expression Language) is an expression language that supports querying and manipulating objects at runtime. This expression language is written within “${ and “}” when used inside annotation…… Continue reading SpEL Simple example
Basic Search in LDAP
In this post under Java LDAP, I will show with example how to perform a basic search for entries in LDAP. I have below ldap tree. In this ldap tree under development department with dn “ou=dev”, I have three developers “user1”, “user2”, and “user3”. “user1” has “description” attribute with value “Softwareengineer 2” whereas “user2” and…… Continue reading Basic Search in LDAP
Searching an array for a particular element
In this post under Java Collections, I will show with example how to search an array for a specific element. Please note there is a precondition that must be satisfied before searching an array. The precondition is that the array should already be sorted. Java “Arrays” class provides “binarySearch” method which does the searching. This…… Continue reading Searching an array for a particular element
Arrays to List conversion
In this post under Java Collections, I will explain with example how to convert an array to list. Please note this conversion is possible if the array is a collection of objects and not primitive elements. To achieve our goal, we use “Arrays” class static method “asList”. This method returns a list backed by the…… Continue reading Arrays to List conversion
Mapping between objects with default value
In this post under MapStruct, I will show with example how to map two objects with default value. Let me further elaborate the requirement. We have “Student” class and we have to map the instance of “Student” class to an instance of “StudentDTO” class. During mapping if the value of “className” attribute in “Student” class…… Continue reading Mapping between objects with default value