MappingConstants.THROW_EXCEPTION example

In this post under MapStruct, I will explain with example the purpose of enum “MappingConstants.THROW_EXCEPTION”. This enum is mainly used when mapping source enum constant to destination enum constant. If you want to throw an exception for some source enum constant. We can use this enum constant. Below is the example showing the usage. Lets…… Continue reading MappingConstants.THROW_EXCEPTION example

Safe navigation operator

In this post under Spring SpEl, I will explain with example the usage of safe navigation operator. Lets say we have below pojo class Employee package spel.package24; public class Employee { private Integer id; private String name; private int salary; public Employee() { } public Employee(Integer id, String name, int salary) { this.id = id;…… Continue reading Safe navigation operator

String to InputStream conversion

In this post under Apache Commons IO, I will show with example how to convert a String to InputStream. “IOUtils” class in Apache Commons IO framework provides a method named “toInputStream” which converts a String to InputStream. This method takes two arguments1) instance of String class2) Charset type Below is the main class showing how…… Continue reading String to InputStream conversion

Using @Singular with @Builder annotation example

In this post under Lombok I will explain with example the purpose of “@Singular” annotation which is alwayse used with “@Builder” annotation. In previous post under lombok I have explained why we use “@Builder” annotation i.e., to implement builder pattern. So if have below pojo class with “@Builder” annotation at the class level Pojo class…… Continue reading Using @Singular with @Builder annotation example

Getting URL of classpath resource

In this post under Apache Commons IO, I will show with example how to get URL of a resource present in application classpath. “IOUtils” class provides a static method “resourceToURL” which takes the resource name and the classloader as arguments and returns url of the resource. Below is the main class showing how to use…… Continue reading Getting URL of classpath resource

Using @Builder annotation example

In this post under Lombok, I will show with example how to use “@Builder” annotation to implement Builder Pattern in our application. For our example, we use the below Person pojo class. Person class package package26; public class Person { private String name; private String city; @Override public String toString() { StringBuilder stringBuilder = new…… Continue reading Using @Builder annotation example