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
Describe the bug
The decodeFromJsonElement function uses the JsonTreeDecoder when element is a JsonObject.
However, the decodeElementIndex function in the JsonTreeDecoder can reach the coerceInputValue function with the explicitNulls = false option and coerceInputValues = true option provided by Json, and the situation of enum parameters with no default value.
In coerceInputValue function, currentElement(tag) can throw NoSuchElementException because currentElement assume that value with tag exist.
I don't think this was intended.
To Reproduce
It's a bit of a contrived situation test, but I think it's good enough to reproduce the situation.
The following tests will fail.
The error still occurs in version 1.5.0.
It is still the same to use currentElement when accessing peekNull, and this is where the error occurs.
A simpler example:
@Serializable
enumclassTestEnum {
ENUM_A, DEFAULT
}
@Test
fun`test`() {
@Serializable
data classTestClass(valtestEnum:TestEnum?)
val jsonString ="""{}""".trimIndent()
val jsonElement =Json {
prettyPrint =false
ignoreUnknownKeys =true
encodeDefaults =true
explicitNulls =false
coerceInputValues =true
}.decodeFromString<JsonElement>(jsonString)
val actualTestClass = deserializeJsonElement<TestClass>(jsonElement)
assertThat(actualTestClass.testEnum).isNull()
}
I've checked on the current dev, and the issue is not present anymore. It was likely fixed by #2530. Also, linking #2586 as a reference — it may be related.
Describe the bug
The decodeFromJsonElement function uses the JsonTreeDecoder when element is a JsonObject.
However, the decodeElementIndex function in the JsonTreeDecoder can reach the coerceInputValue function with the explicitNulls = false option and coerceInputValues = true option provided by Json, and the situation of enum parameters with no default value.
In coerceInputValue function, currentElement(tag) can throw NoSuchElementException because currentElement assume that value with tag exist.
I don't think this was intended.
To Reproduce
It's a bit of a contrived situation test, but I think it's good enough to reproduce the situation.
The following tests will fail.
Environment
The text was updated successfully, but these errors were encountered: