Class JaxrsExceptionMapper
- All Implemented Interfaces:
jakarta.ws.rs.ext.ExceptionMapper<JaxrsException>
JaxrsException to a Response.
The mapped response has the status of the given JaxrsException and media type JSON.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe map key under which the list ofErrorMessageobjects resides. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic jakarta.ws.rs.core.ResponsebuildResponse(JaxrsException exception) Convert the givenJaxrsExceptionto a JSON response.static jakarta.ws.rs.core.Response.ResponseBuilderbuildResponseBuilder(JaxrsException exception) Convert the givenJaxrsExceptionto a JSON response builder.buildResponseEntity(JaxrsException exception) Convert the givenJaxrsExceptionto a map that can be used as a JSON response entity.static JaxrsExceptiontoJaxrsException(int status, Map<String, Object> entity) Convert the given HTTP status code and an entity into aJaxrsException.static JaxrsExceptiontoJaxrsException(jakarta.ws.rs.core.Response response) Convert the givenResponseto aJaxrsException.jakarta.ws.rs.core.ResponsetoResponse(JaxrsException exception) Convert the givenJaxrsExceptionto a response containing a JSON entity.
-
Field Details
-
KEY_ERRORS
The map key under which the list ofErrorMessageobjects resides.- See Also:
-
-
Constructor Details
-
JaxrsExceptionMapper
public JaxrsExceptionMapper()
-
-
Method Details
-
toResponse
Convert the givenJaxrsExceptionto a response containing a JSON entity.- Specified by:
toResponsein interfacejakarta.ws.rs.ext.ExceptionMapper<JaxrsException>- Parameters:
exception- the exception to convert- Returns:
- a response
- See Also:
-
buildResponse
Convert the givenJaxrsExceptionto a JSON response.The response entity contains the information in the JaxrsException.
- Parameters:
exception- the exception to convert- Returns:
- a response
- See Also:
-
buildResponseBuilder
public static jakarta.ws.rs.core.Response.ResponseBuilder buildResponseBuilder(JaxrsException exception) Convert the givenJaxrsExceptionto a JSON response builder.The response entity contains the information in the JaxrsException.
- Parameters:
exception- the exception to convert- Returns:
- a response builder
- See Also:
-
buildResponseEntity
Convert the givenJaxrsExceptionto a map that can be used as a JSON response entity.The response entity will contain an "errors" key containing the
ErrorMessageobjects. If the exception contains any other data (JaxrsException.getOtherData()), those key/value pairs are also included in the response entity. See the note inJaxrsException.setOtherData(Map)regarding the behavior ifotherDatacontains an "errors" key.- Parameters:
exception- the exception to convert- Returns:
- a map that can be used as a response entity
- See Also:
-
toJaxrsException
Convert the givenResponseto aJaxrsException.Attempts to convert a response entity into errors and other data in the resulting exception using
toJaxrsException(int, Map).- Parameters:
response- the response to convert- Returns:
- a new exception instance, or null if the response is null
- See Also:
-
toJaxrsException
Convert the given HTTP status code and an entity into aJaxrsException.Looks for an entry with key "errors" and a list of objects, and attempts to convert them into
ErrorMessageobjects. The conversion from a generic map to anErrorMessageis done usingErrorMessage.valueOf(Map).Any other entries in the map are converted to "other data" in the exception.
- Parameters:
status- the HTTP statusentity- the entity as a map- Returns:
- a new exception instance
- See Also:
-