0

I am invoking API which returns JSON as a response which I am parsing into POJO using Jackson. It is working fine but failing for below JSON array format,

{
...
"data" : [
    {  
        "2017-12-05 21:40:33":"1537"
     },
     {  
        "2017-12-07 23:51:16":"1539"
     },
     {  
        "2017-12-12 22:57:10":"1539"
     }
],
...
}

This date in key is generated at time of data captured in server side, my application invoking API which returns above format of JSON so can you please let me know how I can parse this JSON in Java POJO.

Thanks.

ppb
  • 2,299
  • 4
  • 43
  • 75
  • https://www.mkyong.com/java/jackson-2-convert-java-object-to-from-json/ – Danyal Sandeelo Jan 03 '18 at 06:00
  • Possible duplicate of [How to use Jackson to deserialise an array of objects](https://stackoverflow.com/questions/6349421/how-to-use-jackson-to-deserialise-an-array-of-objects) – Hovercraft Full Of Eels Jan 03 '18 at 06:00
  • Possible duplicate of [How to parse JSON Array (Not Json Object) in Android](https://stackoverflow.com/questions/18977144/how-to-parse-json-array-not-json-object-in-android) – Tinus Jackson Jan 03 '18 at 06:00
  • Thanks for the quick response but mentioned above answers key are fix so I can add it in to POJO as a property but in my case key (which is date) is not fix so every time when I invoke this API I will get different Key in response. – ppb Jan 03 '18 at 06:05
  • has to be parsed in Map – enator Jan 03 '18 at 07:17

1 Answers1

0

Something similar to following.

public class POJO {
    ...
    List<Map<String,String>> data;
    ...   
}

You can also format the key as java.util.Date if needed, registering the date type serializer in the Jaskson's object mapper builder.

enator
  • 2,431
  • 2
  • 28
  • 46