I don’t think there is anything surprising here. S...
# squarelibraries
I don’t think there is anything surprising here. See
- https://github.com/square/moshi/blob/bf72ce8ade0db490136834096e0881d17c87e20a/moshi/src/main/java/com/squareup/moshi/JsonReader.java#L525-L526. You read a number which is converted to a double and passed to be read by a delegate as a string. You need to create a separate adapter that is capable of parsing doubles that will be strings and annotate properties that are of interest. I’m not sure what you expect from
, so I left it as is.
Copy code
annotation class NumberString

object NumberStringAdapter {
  @ToJson fun toJson(@NumberString number: String): String {
    return number
  @FromJson @NumberString fun fromJson(number: String): String {
    return number.toDoubleOrNull()?.toLong()?.toString() ?: number
👍 1