Posted In: Java Script

JS: Finding Number Of Working Days between 2 dates

Leave tracking application often required to calculate number of days between the range of leave dates. To calucalte the actual leave days we exclude weekends and any holidays comming between the date range. Following code take care of both weekends and Public Holidays — <script> var monthNames = {jan:0,feb:1,mar:2,apr:3,may:4,jun:5, jul:6,aug:7,sep:8,oct:9,nov:10,dec:11}; // List of Holiday (Exclude […]

Read More

Tags: Tags:

by , on January 3rd, 2019

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

Tags:

by , on December 5th, 2018

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

Tags:

by , on December 4th, 2018

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 More

Tags: Tags:

by , on December 4th, 2018

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

Tags:

by , on November 27th, 2018

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

Tags:

by , on November 26th, 2018

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 More

Tags: Tags: ,

by , on November 21st, 2018

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

Tags:

by , on November 21st, 2018

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

Tags:

by , on October 21st, 2018

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

Tags:

by , on October 21st, 2018