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 controller and exceptions 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 annotated @ExceptionHandler(value=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 keep order of produce media types and returns application/xml as first media type.

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: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged or decided on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants