Reading file contents as a List of Strings

In this post under Apache Commons IO, I will show with example how to read file contents into a List of Strings. To implement this requirement, the library class “IOUtils” provide with a method named “readLines” This method takes a “FileReader” instance as an argument and return a list of Strings, where each String represents…… Continue reading Reading file contents as a List of Strings

postForObject example

In this post under Spring RestTemplate, I will show with example to make a POST http request. To make a POST http request, Spring RestTemplate framework provides “postForObject” method in “RestTemplate” class. This method takes 3 arguments, which are1) url2) Object to be posted3) Response type Below is the complete main code for your reference.…… Continue reading postForObject example

Adding callback methods in java interface class used as Mapper interface

In previous post under MapStruct I showed with example how to add callback methods in abstract class used as Mapper interface. In this post I will show with example how to add callback methods in interface used as Mapper Interface. For our example I will take the below Pojo class Student package package19; public class…… Continue reading Adding callback methods in java interface class used as Mapper interface

Adding callback methods in abstract class used as Mapper interface

In this post under MapStruct, I will show with example how to add callback methods which will be executed before and after mapping, in abstract class used as Mapper interface. We use two annotations “@BeforeMapping” and “@AfterMapping” to annotate methods which will be called before and after mapping. Lets say for example I have to…… Continue reading Adding callback methods in abstract class used as Mapper interface

delete example

In this post under Spring RestTemplate, I will show with example how to perform DELETE Http request. To perform DELETE http request, we call “delete” method of “RestTemplate”. This method takes only the url with parameter map as optional. Below is the complete main code for your reference Main class package package3; import org.springframework.web.client.RestTemplate; public…… Continue reading delete example

Path Parameter example

In this post under Spring RestTemplate, I will show with example the purpose and how to use path parameter. If we have to make a call to get the “Post” data with id 1 from “http://jsonplaceholder.typicode.com”. Our url will be http://jsonplaceholder.typicode.com/posts/1 Now if I have to make a call to get the “Post” data with…… Continue reading Path Parameter example

getForObject example

In this post under Spring RestTemplate, I will explain with example the purpose of “getForObject” method. “getForObject” method is provided by RestTemplate to make GET HTTP calls. Below is the main method showing how to use it Main class package package1; import org.springframework.web.client.RestTemplate; public class Example1 { public static void main(String[] args) { RestTemplate restTemplate…… Continue reading getForObject example

Reading classpath file contents

In this post under Apache Commons IO, I will show with example how to read the contents of file present in your projects classpath. “IOUtils” class provides a static method named “resourceToString”. This method reads the contents of the file and return a String object. This method takes 3 arguments1) the file name2) the ClassLoader…… Continue reading Reading classpath file contents