:wave: hello hello. I'm having some trouble with ...
# http4k
m
👋 hello hello. I'm having some trouble with a recursive class and generating the openapi definition. I have something like the below example:
Copy code
data class FieldDTO(
    val name: String,
    val obj: ObjectField,
){
    companion object {
        val example = FieldDTO(
            name = "Field",
            obj = ObjectField.example
        )
    }
}

data class ObjectField(
    val name: String,
    val field: FieldDTO? = null,
){
    companion object {
        val example = ObjectField("obj", field = FieldDTO.example)
    }
}
The compiler obviously throws an error on the
ObjectField
example, but if I set the example to be
ObjectField("obj", field = null)
then I get an issue with
NoFieldFound
on generating the openapi as it doesn't like having nulls. Tried to have a search but couldn't find much on what the best approach here is!
a
Can you share the code you use to configure the
renderer
in the contract builder?
m
I'm just using the default, so like
Copy code
renderer = OpenApi3(ApiInfo("Backend", "v1.0", "API"), CustomJackson())
However I was having a play around with passing in a new renderer but wasn't quite playing nicely. If you had any good examples that'd be great
a
The
CustomJackson
might be the issue. The default is
OpenApiJackson
which addresses the null serialization issue. You specifically need to add this to your custom jackson.
Copy code
.setSerializationInclusion(NON_NULL)
🚀 1
m
That's worked a treat, thank you very much!
❤️ 1