I have an entity, defined using a data class:
@Entity
data class BlogPost(
(...)
val title: String,
(...)
val slug: String = title.toSlug(),
)
As per this answer, I expected that a JSON object without a slug
field would deserialize to a BlogPost
whose slug was created using my .toSlug()
extension method – but, to my surprise, the deserialized .slug
ends up being null
even though I thought it wasn't nullable (it's a String
, not a String?
).
I've tried using @JsonInclude(Include.NON_NULL)
, but I suspect this is the wrong tactic, and it only seems to affect serialization; the missing JSON value is still deserialized to null
rather than my default.
I'm on Spring Boot 2.4.3.