Quick revision
The short answer
ProblemDetail is Spring Framework 6's class for the problem details format of RFC 9457, which replaced RFC 7807: an error body with type, title, status, detail and instance, plus any extra properties we add. Controllers and @ExceptionHandler methods can return a ProblemDetail or an ErrorResponse, ErrorResponseException carries one, and ResponseEntityExceptionHandler renders Spring MVC's own exceptions in this format. Spring Boot can turn that on for built-in exceptions with spring.mvc.problemdetails.enabled (spring.webflux.problemdetails.enabled for WebFlux), and responses use the application/problem+json content type.
What to remember
In this answer, we saw that ProblemDetail models the RFC 9457 problem details format with type, title, status, detail, instance and extra properties. Handlers can return ProblemDetail or ErrorResponse, ErrorResponseException carries one, ResponseEntityExceptionHandler renders Spring MVC's own exceptions this way, Spring Boot enables it for built-in exceptions with spring.mvc.problemdetails.enabled or spring.webflux.problemdetails.enabled, and responses use application/problem+json. A consistent error shape is what clients value most.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
ProblemDetail is Spring Framework 6's class for the problem details format of RFC 9457, which replaced RFC 7807: an error body with type, title, status, detail and instance, plus any extra properties we add. Controllers and @ExceptionHandler methods can return a ProblemDetail or an ErrorResponse, ErrorResponseException carries one, and ResponseEntityExceptionHandler renders Spring MVC's own exceptions in this format. Spring Boot can turn that on for built-in exceptions with spring.mvc.problemdetails.enabled (spring.webflux.problemdetails.enabled for WebFlux), and responses use the application/problem+json content type.
Why this question is asked
Every API returns errors, and clients have to parse them. Without a standard, each service invents its own shape, error in one, message in another, code in a third, and every client needs special handling. Problem details is the IETF's standard shape for HTTP API errors, and since Spring Framework 6 it is built in. Interviewers ask about it to see whether we know the format and how Spring wires it, and whether we care about consistency more than about any particular format. In this answer, we will recap the format, see ProblemDetail and ErrorResponse in code, look at how Spring handles its own exceptions, enable it in Spring Boot, and add a machine-readable error code.
1A Quick Recap of the Problem Details Format
RFC 9457, published in 2023 and replacing RFC 7807, defines a JSON object for describing an HTTP API error. It has five standard members. type is a URI that identifies the kind of problem, ideally pointing to documentation; when absent it means about:blank, which says the problem is simply the HTTP status. title is a short human-readable summary of that kind of problem. status repeats the HTTP status code. detail is a human-readable explanation of this particular occurrence. instance is a URI identifying this occurrence, often the request path. Beyond these, a problem can carry extension members, any extra fields that the API defines.
The response uses the media type application/problem+json, so clients can recognise an error body by its content type alone.
| Member | Meaning | Example |
|---|---|---|
| type | URI for the kind of problem | https://api.example.com/problems/order-not-found |
| title | Short summary of that kind | Order not found |
| status | HTTP status code | 404 |
| detail | Explanation of this occurrence | Order 5 does not exist |
| instance | URI of this occurrence | /orders/5 |
| extensions | Any extra members the API defines | errorCode, errors, traceId |
2Returning ProblemDetail From Spring MVC
ProblemDetail is a plain class in spring-web with fields for the standard members and a map of extra properties. We can return it from an @ExceptionHandler, or wrap it in a ResponseEntity, and Spring writes it with the application/problem+json content type. Its status is used as the HTTP status of the response.
If we do not set type, Spring leaves it as about:blank, and if we do not set title, Spring fills in the reason phrase of the status, such as Not Found. Notice that the extra property is written at the top level of the JSON, next to the standard members, as the RFC expects; Spring's Jackson support takes care of that.
3ErrorResponse and ErrorResponseException
ErrorResponse is an interface for anything that can describe itself as an HTTP error: it exposes a status code, headers and a ProblemDetail body. ErrorResponseException is a ready-made RuntimeException that implements it. We can throw it, or subclass it for our own exceptions, and Spring MVC turns it into a problem details response without any handler method.
This keeps the error's HTTP description next to the error itself. Some teams prefer to keep domain exceptions free of HTTP concerns and map them in one @RestControllerAdvice instead; both are reasonable as long as the team picks one.
4Spring's Own Exceptions and ResponseEntityExceptionHandler
Spring MVC raises its own exceptions for framework-level errors: MethodArgumentNotValidException for failed @Valid validation, HttpMessageNotReadableException for malformed JSON, HttpRequestMethodNotSupportedException for a wrong method, NoResourceFoundException for unknown paths in recent versions, and others. Since Spring Framework 6 these implement ErrorResponse, so each carries a ProblemDetail.
ResponseEntityExceptionHandler is a base class for a @ControllerAdvice that handles all of them and renders the problem details. We extend it to get consistent responses for framework errors and override individual methods to enrich them, for example adding field errors to validation failures.
- Exception thrownOurs or Spring MVC's
- Matching @ExceptionHandler?In a
@ControllerAdviceYesHandler returns ProblemDetailNoCheck ErrorResponse - Implements ErrorResponse?Spring MVC exceptions doYesUse its ProblemDetailNoDefault error handling
- Write application/problem+jsonStatus from the
ProblemDetail
4 steps in order. Play them, or step through them one at a time.
ResponseEntityExceptionHandler, or the Spring Boot property, covers Spring MVC's own exceptions.
5Enabling It in Spring Boot
Spring Boot does not switch the format on for everything by default. Setting spring.mvc.problemdetails.enabled=true makes Boot register a ResponseEntityExceptionHandler-based advice, so Spring MVC's built-in exceptions are rendered as problem details without any code. For WebFlux the property is spring.webflux.problemdetails.enabled. If we write our own subclass of ResponseEntityExceptionHandler, as above, we do not need the property, because our advice already does that job.
Notice that the default detail texts are deliberately generic. They avoid leaking internals such as parser messages, which is what we want on a public API. Finally, a word on priorities: the exact error format matters less to clients than having one consistent shape across every endpoint and service. Problem details is a good choice because it is a standard and Spring supports it, but the real win is consistency.
6Follow-up questions
How do you add a machine-readable error code to a ProblemDetail?
With setProperty, for example pd.setProperty("errorCode", "ORDER_NOT_FOUND"), which Spring writes as a top-level member next to type and title. The type URI already identifies the kind of problem, so some teams use it as the code, but a short stable string is easier for clients to switch on. I would define the codes in one place, document them, and never change an existing code's meaning.
Should the detail text be shown to end users?
Usually not directly. detail is meant for developers and may be in English only. Clients should switch on the type or error code and show their own localised message. That is another reason for a stable machine-readable code.
Can we use problem details with Spring Boot's /error page handling?
Errors that never reach Spring MVC's exception handling, such as some servlet container errors, still go through Boot's error controller. With problem details enabled, most MVC errors are covered, but it is worth testing a few edge cases like unknown paths and oversized requests to see what shape they produce in your version.
7Conclusion
In this answer, we saw that ProblemDetail models the RFC 9457 problem details format with type, title, status, detail, instance and extra properties. Handlers can return ProblemDetail or ErrorResponse, ErrorResponseException carries one, ResponseEntityExceptionHandler renders Spring MVC's own exceptions this way, Spring Boot enables it for built-in exceptions with spring.mvc.problemdetails.enabled or spring.webflux.problemdetails.enabled, and responses use application/problem+json. A consistent error shape is what clients value most.
Open with
ProblemDetail is Spring Framework 6's representation of the problem details format from RFC 9457, which replaced RFC 7807. It is a standard JSON error body with type, a URI for the kind of problem that defaults to about:blank, title, status, detail for this occurrence, and instance, plus any extension properties I add with setProperty, which are written at the top level.
Then, if they want more
In Spring MVC I can return a ProblemDetail from an ExceptionHandler, and Spring writes it with the application/problem+json content type and uses its status. There is also the ErrorResponse interface, and ErrorResponseException implements it, so I can throw or subclass it and get a problem response without a handler.
Spring's own exceptions, like MethodArgumentNotValidException or HttpMessageNotReadableException, implement ErrorResponse too, and ResponseEntityExceptionHandler is a base advice that renders all of them as problem details; I extend it to enrich them, for example adding field errors and an errorCode to validation failures. In Spring Boot, spring.mvc.problemdetails.enabled, or the webflux equivalent, turns that on without code.
For a machine-readable code I add an errorCode property with a stable documented value. The main point for clients, though, is one consistent error shape everywhere.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Spring Framework 6
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Framework reference, Spring Web MVC
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "What is ProblemDetail in Spring Framework 6 and how does it relate to error responses in...": https://scrivio-interview-library.netlify.app/spring-boot/rest-api-design/c56108f91b/