spring-projects / spring-projects/spring-boot

Make it easier to control how the keys in the basic error controller's response are formatted

Open
#22,950 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type: enhancement
Dominant language
Java
Stars
81.5k
Forks
42.7k
Avg merge
2d 4h
Merged PRs (30d)
65

Description

I have a Spring Boot 2.3.2.RELEASE WebFlux application. In the application.yml I have these settings:

spring:
  jackson:
    property-naming-strategy: SNAKE_CASE
    serialization:
      write-date-timestamps-as-nanoseconds: false
      write-dates-as-timestamps: true

Indeed, almost any JSON response is sent back to the user-agents correctly: in snake case format, except for the auto-generated ones:

This is a usual GET response from the application:

{
  "port_code": "blah",
  "firm_code": "foo",
  "type": "THE_TYPE",
  "status": "BAR",
}

...this is a custom (intercepted within a @RestControllerAdvice) response for a ConstraintViolationException:

{
    "timestamp": 1597344667156,
    "path": "/path/to/resources/null",
    "status": 400,
    "error": "Bad Request",
    "message": [
        {
            "field": "id",
            "code": "field.id.Range",
            "message": "Identifier must be a number within the expected range"
        }
    ],
    "request_id": "10c4978f-3"
}

...and finally this is how Spring Boot auto-generates an HTTP 404 from a controller (based on a ResponseStatusException, that's what I meant by auto-generated ones 😇):

{
  "timestamp": 1597344662823,
  "path": "/path/to/resources/312297273",
  "status": 404,
  "error": "Not Found",
  "message": null,
  "requestId": "10c4978f-2"     <== NOTICE HERE requestId INSTEAD OF request_id ...what the hell?!
}

This is how I'm triggering that in the controller:

return service.findById(id).switchIfEmpty(Mono.error(new ResponseStatusException(HttpStatus.NOT_FOUND)));

If Jackson is configured in such way, wouldn't that apply across the entire application? Looks like there are parts of it not honouring those settings.

Probably, I missed a configuration setting somewhere, but I can't find anything else, so I decided to file a bug report here — and this is the corresponding StackOverflow question.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with a Spring Boot 2.3.2 WebFlux application using the shown application.yml settings and a ResponseStatusException. Start with the basic error controller and WebFlux error handling, then verify that generated responses, especially requestId, honor the configured snake_case naming; done means the formatting is controllable consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
56/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.