Hey, I was looking around here, documentation and ...
# spring
l
Hey, I was looking around here, documentation and checked how does openapi-generator does it - and still everywhere the DTOs for Spring are using nullable fields with defaults, is there a better way to make json handle data classes? openapi does it like this
Copy code
data class Pet (

        @get:NotNull 
        @JsonProperty("name") val name: kotlin.String,

        @get:NotNull 
        @JsonProperty("photoUrls") val photoUrls: kotlin.collections.List<kotlin.String>,

        @JsonProperty("id") val id: kotlin.Long? = null,

        @JsonProperty("category") val category: Category? = null,

        @JsonProperty("tags") val tags: kotlin.collections.List<Tag>? = null,

        @JsonProperty("status") val status: Pet.Status? = null
)
m
If you're using Jackson, ensure yoy add the Jackson kotlin module. Spring boot will emit a warning if it finds kotlin and no Jackson module. Think it was 2.1+ that it does that. Would have to look at docs for other libraries if you're not using Jackson.