
Posted In: GSON, JSON
How to map multiple date formats using Gson?
Use Case – I want to map multiple date formats to Gson while converting date string to POJO Use Jackson if possible for this requirement. It has much easier to use annotations to achieve this how-to-map-multiple-date-formats-using-jackson-mapper Maven – Gson Solution – Use JsonDeserializer JsonDeserializer, gsonBuilder.registerTypeAdapter(Date.class, new DateDeserializer()) and SimpleDateFormat
Read More
Posted In: GSON, JSON
How to map date format using Gson
Use Case – I want to map particular date format to Gson while converting date string to POJO Maven – Gson Solution GsonBuilder().setDateFormat()
Read More
Posted In: GSON, JSON
Is Gson threadsafe?
Use Case – I want to make only one/few Gson objects and share them in various classes. Comment from Gson class Maven – Gson Test which failed in prior versions of GSON https://groups.google.com/forum/#!topic/google-gson/Vju1HuJJUIE
Read MoreTags: Is it ok to declare Gson as a spring singleton? Is it ok to declare Gson as a static field?

Posted In: Jackson 2X, JSON
How to map multiple date formats using Jackson Mapper?
Use Case – I want to map multiple date formats to ObjectMapper while converting date string to POJO Maven – Jackson 2X Solution – Use @JsonFormat @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = “yyyy-MM-dd”, timezone = “IST”)
Read More
Posted In: Jackson 2X, JSON
How to map date format using Jackson Mapper
Use Case – I want to map particular date format to ObjectMapper while converting date string to POJO Maven – Jackson 2X Solution ObjectMapper .. mapper.setDateFormat(SimpleDateFormat);
Read More
Posted In: Jackson 2X, JSON
Is Jackson ObjectMapper threadsafe?
Use Case – I want to make only one/few ObjectMapper objects and share them in various classes. In this case we could use immutable ObjectReader and ObjectWriter classes Comment from ObjectWriter class Maven – Jackson 2X Solution – com.fasterxml.jackson.databind.ObjectWriter ObjectWriter objectWriter = mapper.writer(); ObjectReader objectReader = mapper.reader().forType(Employee.class);
Read MoreTags: Is it ok to declare ObjectMapper as a spring singleton?, Is it ok to declare ObjectMapper as a static field?

Posted In: Jackson 2X, JSON
Create custom serializer using Jackson 2.X
Use Case – While creating JSON from POJO I want to add additional logic or fields to the JSON. In the following example let us add full name which is concatenation of first name and last name. In such cases we could use Jackson custom serializer class. Maven – Jackson 2X Solution – com.fasterxml.jackson.databind.ser.std.StdSerializer Following […]
Read More
Posted In: Java Core
How to print java object without getting object name like SomeType@
There are three possible ways 1. Override toString method in your class/pojo @Override public String toString() 2. Use org.apache.commons.lang.builder.ToStringBuilder 3, Use Arrays.toString to print values from string array
Read More
Posted In: Java Core, String
How to replace string inside curly brackets
Three possible ways 1. Use replace function. In this case do not escape curly brackets 2. Use replaceAll function. In this case escape curly brackets because replaceAll uses regular expression 3. Use java.text.MessageFormat class if string to replace is like {0}, {1}, {2} This code snippets were useful while testing Spring Rest URLs with a […]
Read More
Posted In: GSON, JSON
GSON – How to parse input JSON with dynamic keys
Use Map to parse this JSON. This will work as JSON cannot have duplicate keys.
Read More- Apache (13)
- Build Tools (2)
- Gradle (2)
- Caching (1)
- cpanel (1)
- cURL (1)
- Database (7)
- Hibernate (5)
- Java Core (38)
- Java Script (15)
- Bootstrap (1)
- File Upload (7)
- jQuery (3)
- React (3)
- JEE (13)
- JSON (41)
- GSON (13)
- Jackson 1X (1)
- Jackson 2X (12)
- jsoniter (1)
- Logging (2)
- Apache Commons Logging (1)
- Apache Log4J (1)
- Logback (1)
- SLF4J (1)
- MongoDB (1)
- OS (1)
- Linux (1)
- Security (5)
- Server (4)
- Tomcat (4)
- Service (2)
- Micro (2)
- Spring (46)
- Pattern (2)
- Spring Boot (20)
- Spring Data (4)
- Spring MVC (8)
- Spring REST (13)
- Spring Security (7)
- Testing (11)
- XML (5)
- JDOM XML Parser (1)