You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Extension property JsonPrimitive.intOrNull returns an invalid value instead of null when the content string starts with a digit
To Reproduce
@Serializable
class SomeData(
@SerialName("number")
val number: Int
)
val someData2 = Json.decodeFromString<SomeData>("""{"number": "3 digit then random string"}""")
someData2.number == 3 // true
the actual value in the number field is 3
Expected behavior
the expected value in the number field is 3
Environment
Kotlin version: 1.9.10
Library version: 1.6.0+
Kotlin platforms: JVM
The text was updated successfully, but these errors were encountered:
Hi, can you please clarify the issue? I do not see any usages of JsonPrimitive.intOrNull in your code. decodeFromString function tries to map input directly onto @Serializable class. If a value cannot be converted to Int, an exception is thrown. "3 digit then random string" cannot be converted to Int, because it is not appropriate to convert only a part of the string.
Extension property JsonPrimitive.intOrNull returns an invalid value instead of null when the content string starts with a digit
To Reproduce
the actual value in the number field is 3
Expected behavior
the expected value in the number field is 3
Environment
The text was updated successfully, but these errors were encountered: