Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

json string with multiple types to Map[String, Object]

Tags:

java

json

jackson

I have this json string:

{
  "startDate" : "2014-12-17T14:31:40Z",
  "name" : "Izek",
  "age" : 12
}

When I convert it with Jackson to Map[String, Object] the type of startDate is String how I can tell Jackson to convert it to DateTime type?

like image 516
igreenfield Avatar asked May 19 '15 06:05

igreenfield


2 Answers

You need to explicitly set the data format in the objectMapper. You could refer Date format Mapping to JSON Jackson for more details. Alternately, you could do it as http://java.dzone.com/articles/how-serialize-javautildate

like image 163
Balaji Katika Avatar answered Sep 27 '22 19:09

Balaji Katika


Have you considered a custom map deserializer? You can try to parse the date in there. If not known in advance, you'll probably hit a performance hit here.

like image 38
YaOg Avatar answered Sep 27 '22 19:09

YaOg