Closed dlurton closed 1 year ago
You're right that it is both very close to the other issue, but it is slightly different. The other issue was meant to be more illustrative of the problems with nullable::
in general. I think the root cause it the same though.
There are some types for this Ion Schema Kotlin is unable to determine a "base type" to use for the purpose of allowing a typed null. In Ion Schema Kotlin, this results in a SO Error because it naively tries to find the base type of e.g. any
(which is a union of all types) and so there is no single Ion type that is the "base type" for any
.
You can deal with this in a few different of ways. One would be to make the type
explicit in the nullable::
-annotated type definition. E.g.:
type::{
name: bat,
any_of: [
nullable::{type:string, valid_values: ["a"]}
]
}
If you are specifically dealing with an inline type that has only a valid_values
constraint, you can simply add the desired null values to the list instead of using nullable::
. E.g.:
type::{
name: bat,
any_of: [
{valid_values: ["a", null, null.string]}
]
}
Alternately, you can use Ion Schema 2.0, which drops nullable::
(because it was confusing, and it's sometimes not possible to find the correct "base type") in favor of $null_or::
which is syntactical sugar for the union of the decorated type and the $null
type.
Do any of those solutions work for you?
This might be a duplicate of https://github.com/amazon-ion/ion-schema-kotlin/issues/169 but I thought I'd file an issue anyway since the situation appears to be slightly different (I'm not specifying any specific Ion or core type here)... I discovered this while attempting to place a constraint on a nullable field that only applied when the value was not null.
The first call to
validate()
print indicates"null"
is not valid for thebat
type (unexpected--the type isnullable::
, the second call (different only by the typedness of the null value) results in a stack overlfow.Output: