Trying to deserialise some JSON and encounter this...
# jackson-kotlin
n
Trying to deserialise some JSON and encounter this error:
Copy code
com.fasterxml.jackson.databind.exc.MismatchedInputException: Expected array or string.
 at [Source: (StringReader); line: 5, column: 19] (through reference chain: org.example.battery_info.cli_client.BatteryInfoResult["batteryInfoList"]->java.lang.Object[][0]->org.example.battery_info.cli_client.model.http.BatteryInfo["timestamp"])
What does this error mean?
Sample JSON obtained via Postman, which has been truncated for brevity.
Below are the key data classes that represent the models:
Copy code
data class BatteryInfo(
    val id: Int,
    val timestamp: LocalDateTime,
    val channel: Int,
    val battery: Battery,
    val site: Int
)

data class BatteryInfoResult(val total: Int, val batteryInfoList: Array<BatteryInfo>)
Already have the JavaTime module registered in the ObjectMapper, which makes the error all the more puzzling.
Looks as though I might need to create a custom deserializer for java.time.LocalDateTime. How do I create a custom deserializer that can deserialize a JSON object to a Kotlin object?
Seems that the JavaTime module is expecting a array and not a object. Isn't there only one way a LocalDateTime instance can be serialized using Jackson?
Implemented a data class (Timestamp) to act as a workaround that captures some of the JSON properties:
Copy code
@JsonIgnoreProperties(ignoreUnknown = true)
data class Timestamp(
    @JsonProperty("year")
    val year: Int,
    @JsonProperty("monthValue")
    val month: Int,
    @JsonProperty("dayOfMonth")
    val day: Int,
    @JsonProperty("hour")
    val hour: Int,
    @JsonProperty("minute")
    val minute: Int
)