Jackson deserialization of missing JSON number value to 0.0 in Spring

Viewed 55

I have defined a Kotlin data class like this:

@JsonIgnoreProperties(ignoreUnknown = true)
data class MandatoryLimits(

  val upper: Double,

  val lower: Double

)

as part of a compound object that my Spring service receives as a request body in a POST request. When I send a test request with one value missing, e.g. like this:

           "specificationLimits": {
                "lower": 1.6
            }

then I receive a correctly deserialised object of Type MandatoryLimits, but the missing value is set to simply 0.0.

I would have expected to get a BAD REQUEST from the service, instead. Do I need to configure something in addition?

Thanks in advance for all your help!

1 Answers

As a workaround I defined the data class members as nullable and added an init Block to validate the presence of both values. In case of an error, I throw the response exception manually.

Related