Skip to content

Conversation

IMurzich
Copy link

@IMurzich IMurzich commented Oct 8, 2025

Fix error when corrupt order of produces media types for @ExceptionHandler.

For example, the following returns xml by default.

@ExceptionHandler(exception = Exception.class,
    produces = {"application/json", "application/xml"})

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 8, 2025
@sbrannen sbrannen changed the title Keep order of produce media types in Exeception handler Retain order of produces media types in @ExceptionHandler Oct 8, 2025
@sbrannen sbrannen added status: waiting-for-feedback We need additional information before we can continue in: web Issues in web modules (web, webmvc, webflux, websocket) labels Oct 8, 2025
@sbrannen
Copy link
Member

sbrannen commented Oct 8, 2025

Hi @IMurzich,

Congratulations on submitting your first PR for the Spring Framework! 👍

However, before we process this PR, we need to take care of the following.

  1. Please explain the error scenario you are attempting to fix.
  2. Please introduce a unit or integration test which fails before the fix and passes after the fix.

Regarding point # 1, I realize you added some text to this issue's description, but it is not fully clear to me what you mean. So, perhaps you can just expound on that.

Thanks

@sbrannen sbrannen marked this pull request as draft October 8, 2025 14:56
@IMurzich
Copy link
Author

IMurzich commented Oct 8, 2025

Hi @sbrannen,

I've added test. Please check it.

Thanks.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Oct 8, 2025
@IMurzich IMurzich marked this pull request as ready for review October 8, 2025 15:44
@IMurzich
Copy link
Author

IMurzich commented Oct 8, 2025

Purpose of change:

I have a controller and exception handler in it.

My REST service can return JSON or XML replies.

Therefore I want to return exceptions in JSON or XML too.

Exception handler is annotated with:

@ExceptionHandler(exception = Exception.class, produces = {"application/json", "application/xml"})

And I expect to get JSON response with error (accept=*/*), but I receive XML response because HashSet doesn't retain the order of the produces media types and returns application/xml as the first media type.

@sbrannen sbrannen self-assigned this Oct 10, 2025
@sbrannen sbrannen added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on status: feedback-provided Feedback has been provided labels Oct 10, 2025
@sbrannen sbrannen added this to the 6.2.12 milestone Oct 10, 2025
@sbrannen sbrannen added type: bug A general bug and removed type: enhancement A general enhancement labels Oct 11, 2025
@sbrannen
Copy link
Member

sbrannen commented Oct 11, 2025

@IMurzich, can you please sign off your commits so that the Developer Certificate of Origin (DCO) check passes?

Thanks

@sbrannen sbrannen added the status: waiting-for-feedback We need additional information before we can continue label Oct 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: web Issues in web modules (web, webmvc, webflux, websocket) status: waiting-for-feedback We need additional information before we can continue type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants