validation: Fix @JsonProperty(required = true)
annotation on primitives
#97
Labels
bug
Something isn't working
Milestone
Ideally, Kotlin's nullable type system would be enough to dictate which fields are required and which are optional. However, this logic doesn't work on primitives (Boolean, Int, Long, etc.) because Jackson (our json mapper) transforms a missing value into the default one (false for boolean, 0 for numbers, etc.). That's why we're currently using
@JsonProperty(required = true)
on those fields. In a sad try to be consistent, we even added the annotation to all required fields, even though most of them weren't even necessary.There are 2 problems with this approach:
My suggestion is to create a custom ConstraintValidator annotation (e.g.
@RequiredPrimitive
) that checks if the converted value is missing and sends a readable message error. Note, however, that this implementation might not be trivial since it might have to process some custom mapping, so consider other options. There might also be some existing annotation that I'm not aware of, so make sure to research this matter.In worst-case scenario, we could at least create a wrapper annotation of
@JsonProperty(required = true)
with a different nameThe text was updated successfully, but these errors were encountered: