The situation is:
- Kotlin
- REST API with request/response objects generated from OpenAPI schema (so there is a limited ability to modify them)
The generated response object looks like this:
@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY)
data class Foo (
@field:JsonProperty("version") val version: kotlin.Int,
@field:JsonProperty("bar") val bar: kotlin.collections.List<FooBar>,
...
)
- Null values and empty collections omitted from serialized response by
JsonInclude(NON_EMPTY)
, to reduce network load. - ObjectMapper with jackson-module-kotlin
I want to write end-to end tests of the API using ktor client. It would be convenient, if I could deserialize the http response body to response class.
However, it is not possible, because jackson was unable to fill required fields (in this case empty arrays)
value failed for JSON property bar due to missing (therefore NULL) value for creator parameter bar which is a non-nullable type
Is there a way to introduce default values, either globally like ‘null for non-null List is listOf()’ or per-field default values in generated response objects?