I have scenario where i need to store the dynamic attributes into the database in the form of HashMap given by the user using a rest service. This dynamic attributes is defined as
HashMap<String, Object> attr = new HashMap<>();
Now, I have to convert the object into their respective run time data types according to the business logic. So far, I am able to succeed in converting strings, numbers but Date is causing trouble. This is my conversion logic.
input = attr.get(label);
if (input instanceof String) {
// logic 1
}
else if (input instanceof Number) {
// logic 2
}
else if (input instanceof Date) {
// logic 3
}
The problem is when date is given in the any date format (in my case zulu format) the jacksonjson converter is unable to parse it and throws error stating cannot parse the input string.
I understand that it had been a Date object. I could have written a JsonDeserializer and annotate the Date object with it, but since it is a Object within a HashMap how should i achieve this.
I have also tried catching that date string and parsing it using a SimpleDateFormat but failed since the exception occurs way before this logic.
JSONpayload and how to you deserialise it? If you useMap<String, Object>as result from deserialisation process there is no possibility thatJacksonwill find out that this is a date. It should be aString.