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
Author: sumanthprabhakar
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
Mapping using builder pattern
In all my previous post under MapStruct, whenever MapStruct has to create a target object it used constructor. What if the target class follows builder pattern instead of using a simple constructor. In this post under MapStruct where object is mapped from source to destination class. I will show with example how to instruct MapStruct…… Continue reading Mapping using builder pattern
PUT example
In this post under Spring REST Template, I will show with example how to perform http PUT operation. For our example I will be updating a “Post” object with id 1 at resource “http://jsonplaceholder.typicode.com/posts”. Below is the class structure of “Post” class. Post package package7; public class Post { private int id; private String title;…… Continue reading PUT example
Writing String data to an output stream
In this post under Apache Commons IO, I will show with example how to write String data to an output stream. The Apache Commons IO library, provides a overloaded static method “write” under “IOUtils” class. We can use this method to write String data to an output stream. Its just a one line of code.…… Continue reading Writing String data to an output stream
postForLocation example
In this post under Spring RestTemplate, I will explain with example the purpose of “postForLocation” method in “RestTemplate” class. The “postForLocation” method is similar to “postForObject” both are used to perform a POST request. The only difference is “postForLocation” method returns a url which points to the location where the newly created resource can be…… Continue reading postForLocation example
InheritInverseConfiguration annotation example
In this post under MapStruct I will explain with example the purpose of “InheritInverseConfiguration” annotation. Lets say you have Mapper interface that has declared a method whose purpose is to map properties of “Student” to properties of “StudentDTO”. You have used “@Mapping” annotation on the method to tell MapStruct how to map property that differ…… Continue reading InheritInverseConfiguration annotation example