Skip to content

Error response that's not a Problem can't be treated by Jackson 3 #246

@pvdbosch

Description

@pvdbosch

I'm testing impact of Jackson 3.

There's an issue occurring when an API returns a 4xx/5xx status without a "status" property in the JSON payload.
Problem has a status with int type. When the property is absent from the JSON payload, it can't be set to null.

Caused by: tools.jackson.databind.exc.MismatchedInputException: Cannot map `null` into type `int` (set DeserializationConfig.DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES to 'false' to allow)
 at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); byte offset: #1] (through reference chain: io.github.belgif.rest.problem.DefaultProblem["status"])
	at tools.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:67)

This is different from Jackson 2 behavior , where the default config for FAIL_ON_NULL_FOR_PRIMITIVES was false. It'll probably set status to 0 if it's absent (haven't tested). The new Jackson 3 behavior does make sense to me.

What would be the best solution?

  • We set the status to the http header's status when it's absent from the payload?
  • Change the type of status to Integer and set it to null?
  • Set to 0 when absent?
    • note: @JsonProperty(value = "status", defaultValue = "0") doesnt work. defaultValue is only for documentation, not deserialization

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions