Encountering this JSON deserialization error messa...
# jackson-kotlin
n
Encountering this JSON deserialization error message: Cannot construct instance of
org.example.battery_info.model.http.SensorDataTimestampRangeBody
(although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('{"owner":"Joe Bloggs","site":"House","timestampRange":{"endDay":3,"endHour":12,"endMinute":0,"endMonth":5,"endYear":2019,"startDay":2,"startHour":12,"startMinute":0,"startMonth":5,"startYear":2019}}'
Upon inspection the JSON structure matches correctly to the data classes yet deserialization fails when the Android client makes a HTTP request. The CLI client works fine without any issues. Is there a way to fix the JSON deserialization issue? Is the issue related to this GitHub issue ( https://github.com/FasterXML/jackson-module-kotlin/issues/91 )?
SensorDataTimestampRangeBody model:
Copy code
data class SensorDataTimestampRangeBody(val owner: String, val site: String, val timestampRange: TimestampRange)
TimestampRange model:
Copy code
data class TimestampRange(
    val startYear: Int,
    val startMonth: Int,
    val startDay: Int,
    val endYear: Int,
    val endMonth: Int,
    val endDay: Int,
    val startHour: Int,
    val startMinute: Int,
    val endHour: Int,
    val endMinute: Int
)
m
Jackson is complaining that you’re trying to deserialize from a String.
The json structure is probably fine but it’s inside a String — see the quotes in the error message around the curlies
Perhaps content type is not set on the Android client?
n
Discovered with the Android client that it is producing a String instead of a Object. I have rectified the issue and have had no issues since 😄.