In this post under DotEnv I will show with example what is the purpose of “ignoreIfMalformed” method with an example. If the “.env” is not properly formed i.e., if there is syntax error. The default behavior of DotEnv framework is to thrown an exception. We can change this default behavior. We can configure DotEnv to…… Continue reading DotenvBuilder ignoreIfMalformed example
Month: June 2025
Getting generic class instance as response
In all my previous post under Spring RestTemplate, I got response as Java objects which were non-generic classes. Below is an example for your reference ResponseEntity<Post> postResponseEntity = restTemplate.exchange(url, HttpMethod.POST, httpEntity, Post.class); System.out.println(postResponseEntity.getBody()); When we call “getBody” method, we get an instance of “Post” class. “Post” is not a generic class. What if we want…… Continue reading Getting generic class instance as response
Mapping between objects with expressions
In this post under MapStruct, I will show with example how to add expressions in “@Mapping” annotation. For our example we will use the below classes Student package package24; import java.util.Date; public class Student { private int id; private String name; //Removed getter, setter, and toString for brevity } StudentDTO package package24; import java.util.Date; public…… Continue reading Mapping between objects with expressions
Setting request headers example
In this post under Spring RestTemplate, I will show with example how to set request headers. In our previous posts under Spring RestTemplate, I have covered the below methods1) getForObject2) postForObject3) getForEntity4) put5) postForLocation6) postForEntityetc None of these above methods provide you the option of setting request headers. So to achieve this we use the…… Continue reading Setting request headers example
Mapping between objects with default and constant date value
In this post under MapStruct, I will show with example how to map a date as default and constant value. Below is the source class Student package package23; import java.util.Date; public class Student { private int id; private String name; //Removed getter, setter, and toString for brevity } The “Student” class has one field named…… Continue reading Mapping between objects with default and constant date value
Verifying a method never invoked
In this post under Mockito I will show with example how to verify non-invocation of a method. For our example we will use the below class Class14 package package14; public class Class14 { public void method1(boolean invoke) { if(invoke) display(); } public void display() { } } In the above class, we have two methods…… Continue reading Verifying a method never invoked
DotenvBuilder systemProperties method example
In this post under DotEnv, I will show with example the purpose of “systemProperties” method available in DotEnv framework. With the help of this method whatever properties you read from .env file can be added as System properties and accessible using “System.getProperty()” method. Below is the main class showing how to use it Main class…… Continue reading DotenvBuilder systemProperties method example
getForEntity example
In this post under Spring RESTTemplate, I will show with example the purpose of “getForEntity” method available on “RestTemplate” class. In our previous post, we have to make a GET http call, we used “getForObject” method available on “RestTemplate” class. But “getForObject” method only returns response body and not the header information. To get header…… Continue reading getForEntity example
Mapping between objects with constant value
In this post under MapStruct, I will show with example how to map between objects with constant value. Lets say you have to map “Student” object to “StudentDTO” object. Below is the class structure for your reference. Student package package22; public class Student { private int id; private String name; //removed getter, setter, and toString…… Continue reading Mapping between objects with constant value
Skipping data while reading
In this post under Apache Commons IO, I will explain with example how to skip certain amount data while reading. We can use static “skip” method available as part of “IOUtils” class. This method takes two arguments1) the reader from where it is reading data. The reader can be byte or character stream2) the number…… Continue reading Skipping data while reading