更新时间:2022-02-22 18:00:32
您需要具有一个与JSON***匹配的外部对象.在这种情况下,请将您的代码更改为:
You need to have an outer object that matches the top level of the JSON. In this case change your code to:
data class ActivityConfig(
@JsonProperty("activities-steps") val steps: List<ActivitiesSteps> = emptyList()
)
data class ActivitiesSteps(var dateTime: String, var value: String)
val stepsList = mapper.readValue<ActivityConfig>(jsonSteps).steps
如果希望列表始终存在,则可以将默认值与Jackson Kotin模块一起使用,并且如果需要,您也不需要数据类中的var
成员,val
也可以与Jackson一起正常工作除非您真的想要更改这些值.
You can use default values with the Jackson Kotin module if you want the list to always be present, and also you do not need var
members in the data class if you want, val
work fine with Jackson as well unless you really want to mutate the values.