Skip to content

ProblemDetailJacksonMixin not configured on Jackson JsonMapper #47298

@fbus

Description

@fbus

This is a regression from spring boot 4.0.0-M3

Description

DemoApplication.java

I add custom properties to my ProblemDetail errors.

With the sample code attached, on 4.0.0-M3 I get this :

{
  "detail": "Simulated error",
  "instance": "/hello",
  "properties": {
    "customProperty": "Custom Value"
  },
  "status": 400,
  "title": "OH NOOOOO :(",
  "type": null
}

expected result (from 4.0.0-M2)

{
  "title": "OH NOOOOO :(",
  "status": 400,
  "detail": "Simulated error",
  "instance": "/hello",
  "customProperty": "Custom Value"
}

As you can see there is a "properties" node which should not be there

My analysis

HttpMessageConvertersAutoConfiguration creates an HttpMessageConverters instance based on :

  1. HttpMessageConverter from the context (additionalConverters)
  2. default HttpMessageConverter list

In both cases there is a JacksonJsonHttpMessageConverter, as shown here:

Image \

The first one (from additionalConverters) takes precedence, and is created by JacksonHttpMessageConvertersConfiguration. It uses the JsonMapper created in JacksonAutoConfiguration
using configuration properties (spring.jackson.* )
It doesn't add support for ProblemDetailJacksonMixin.

On the other hand, the 2nd JacksonJsonHttpMessageConverter created with default constructor adds ProblemDetailJacksonMixin

solution

Well, I'm not sure. Maybe JsonMixinModuleEntries should add the ProblemDetailJacksonMixin if it's found in classpath ? (or handle something with @ConditionalOnClass(ProblemDetailJacksonMixin.class) ?)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions