In this post under Spring Core, I will show with example how to apply “@Value” annotation on a constructor parameter. In my previous post under Spring Core, I have showed how to apply “@Value” annotation on class instance variable. Below is the complete main class showing how to apply “@Value” annotation on a constructor parameter…… Continue reading Appling @Value on constructor parameter
IOUtils copyLarge method
In this post under Apache Commons IO, I will show with example the purpose of static method “copyLarge” available in “IOUtils” class. In our previous post under Apache Commons IO, we already covered “copy” method available in “IOUtils” class. The purpose of both the methods is same i.e., copy the contents of one file into…… Continue reading IOUtils copyLarge method
IOUtils writeLines method
In this post under Apache Commons IO, I will show with example the purpose of “writeLines” static method available in “IOUtils” class “writeLines” method takes a list of Objects and writes them to outputstream or writer. For each object to be written, it calls its “toString” method to get the String representation of the object…… Continue reading IOUtils writeLines method
DotenvBuilder ignoreIfMalformed example
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
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
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