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
I trying to decode some JSON with com.beust:klaxon:5.5 and bail out If I get something invalid, however in Klaxon().parse I don't get a null but a inner exception:
Caused by: java.lang.NullPointerException: null cannot be cast to non-null type kotlin.Any
at com.beust.klaxon.JsonObjectConverter.calculatePolymorphicClass(JsonObjectConverter.kt:233)
at com.beust.klaxon.JsonObjectConverter.initIntoUserClass(JsonObjectConverter.kt:55)
at com.beust.klaxon.JsonObjectConverter.fromJson(JsonObjectConverter.kt:30)
at com.beust.klaxon.DefaultConverter.fromJsonObject(DefaultConverter.kt:223)
at com.beust.klaxon.DefaultConverter.fromJson(DefaultConverter.kt:40)
at com.beust.klaxon.Klaxon.fromJsonObject(Klaxon.kt:296)
The code for trigger this:
data classCoordinates(vallat:Double, vallong:Double)
data classJsonError(valkind:String, valmessage:String)
@TypeFor(field ="type", adapter =QueryTypeAdapter::class)
openclassQuery(valtype:QueryType)
data classStartTravel(valfrom:Coordinates, valto:Coordinates): Query(QueryType.StartTravel)
data classFail(valerror:JsonError): Query(QueryType.Fail)
classQueryTypeAdapter: TypeAdapter<Query> {
overridefunclassFor(type:Any): KClass<outQuery> =when(type asQueryType) {
QueryType.StartTravel->StartTravel::classQueryType.Fail->Fail::class
}
}
privatefundecode(json:String):Query {
val obj =Klaxon().parse<Query>(json) <---HERE
obj ?:returnFail(
JsonError(
kind ="Json",
message ="Invalid JSON:$json"
))
return obj
}
and the invalid json:
{"Fail":{"kind":"JSON","message":"unknown variant `from`, expected one of `StartTravel`, `SearchingDriver`, `Fail` at line 1 column 7"}}
The text was updated successfully, but these errors were encountered:
I trying to decode some JSON with
com.beust:klaxon:5.5
and bail out If I get something invalid, however inKlaxon().parse
I don't get a null but a inner exception:The code for trigger this:
and the invalid json:
The text was updated successfully, but these errors were encountered: