In this post under Spring RestTemplate, I will show with example how to pass query paramter. For our example I will perform a GET http request on url “http://jsonplaceholder.typicode.com/posts” with “userId” as query parameter. I will create a url template and then create a map which will contain an entry where key will be “userId”…… Continue reading Query Parameter example
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
Using Abstract class as Mapper interface
In this post under MapStruct, I will show with example how to use java abstract class as Mapper interface. In all my previous posts under MapStruct, I have shown you how to create Mapper interface (interface annotated with @Mapper annotation) using java interface. In this class I will use java abstract class to define the…… Continue reading Using Abstract class as Mapper interface
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
Reading classpath file contents as bytes
In this post under Apache Commons IO, I will show with example how to read the contents of file present in your projects classpath as bytes. “IOUtils” class provides a static method named “resourceToByteArray”. This method reads the contents of the file as bytes. This method takes two arguments1) the file name2) the ClassLoader instance…… Continue reading Reading classpath file contents as bytes
Reading file contents using Iterator
In this post under Apache Commons IO, I will show with example how to read file contents using Iterator. “IOUtils” provides a static method named “lineIterator” which reads the file and returns an “Iterator” object. Each item returned by this iterator represent a line in the file. Using the “Iterator” object we can iterate the…… Continue reading Reading file contents using Iterator
MappingConstants.ANY_REMAINING
In this post under MapStruct, I will explain with example the purpose of “MappingConstants.ANY_REMAINING” enum constant. This enum constant is basically used when mapping source enum constant to destination enum constant. This enum constant is used in mapping interface to represent enum constants which don’t have explicit “@ValueMapping” annotation. Let me explain with an example…… Continue reading MappingConstants.ANY_REMAINING
List Fill demo
In this post under Java Collections, I will explain with example the purpose of “fill” static method in “Collections” utility class. This method takes any list as input and replace all the elements of the list with user given object. So if we have a list named “entries” containing below elements [1, 2, 3, 4,…… Continue reading List Fill demo