I am getting a json string from Fitbit API. I want to save dateTime and value fields in a List object. I´m using jackson module kotlin. I have created ActivitiesSteps data class for this.
I don´t know how to avoid "activities-steps" field and I´m getting stucked.
This is the JSON body(provided in variable 'jsonSteps' to readValue method in my code below):
{
"activities-steps":[
{
"dateTime":"2018-04-17",
"value":"11045"
},
{
"dateTime":"2018-04-18",
"value":"14324"
},
{
"dateTime":"2018-05-16",
"value":"11596"
}
]
}
Here is my class to save my data:
data class ActivitiesSteps(var dateTime: String, var value: String)
Here is my code using jackson:
val mapper = jacksonObjectMapper()
val stepsList = mapper.readValue<List<ActivitiesSteps>>(jsonSteps)
And the following exception is thrown:
Exception in thread "main" com.fasterxml.jackson.databind.exc.MismatchedInputException:
Cannot deserialize instance of `java.util.ArrayList` out of
START_OBJECT token at
[Source: (String)"{"activities-steps":[
{"dateTime":"2018-04-17","value":"11045"},
{"dateTime":"2018-04-25","value":"8585"},
{"dateTime":"2018-04-26","value":"11218"},
{"dateTime":"2018-04-27","value":"10462"},
{"dateTime":"2018-04"[truncated 762 chars]; line: 1, column: 1]