forked from airlift/airlift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove custom Json mapper and smile support
This reuses Jackson provided Jakarta provider
- Loading branch information
Showing
11 changed files
with
118 additions
and
562 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
165 changes: 0 additions & 165 deletions
165
jaxrs/src/main/java/io/airlift/jaxrs/AbstractJacksonMapper.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package io.airlift.jaxrs; | ||
|
||
import com.fasterxml.jackson.core.JacksonException; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.core.exc.StreamReadException; | ||
import com.fasterxml.jackson.core.exc.StreamWriteException; | ||
import com.fasterxml.jackson.databind.JsonMappingException; | ||
import com.fasterxml.jackson.databind.exc.PropertyBindingException; | ||
import jakarta.ws.rs.core.Response; | ||
import jakarta.ws.rs.ext.ExceptionMapper; | ||
|
||
public class JacksonMapper | ||
implements ExceptionMapper<JacksonException> | ||
{ | ||
@Override | ||
public Response toResponse(JacksonException exception) | ||
{ | ||
return switch (exception) { | ||
// User errors | ||
case StreamReadException streamReadException -> Response.status(Response.Status.BAD_REQUEST) | ||
.entity(formatErrorMessage(streamReadException, "Could not read JSON value")).build(); | ||
case PropertyBindingException propertyBindingException -> Response.status(Response.Status.INTERNAL_SERVER_ERROR) | ||
.entity(formatErrorMessage(propertyBindingException, "Could not bind JSON value")).build(); | ||
// Server errors | ||
case StreamWriteException streamWriteException -> Response.status(Response.Status.BAD_REQUEST) | ||
.entity(formatErrorMessage(streamWriteException, "Could not write JSON value")).build(); | ||
case JsonMappingException mappingException -> Response.status(Response.Status.INTERNAL_SERVER_ERROR) | ||
.entity("Could not map JSON value: " + mappingException.getMessage()).build(); | ||
default -> Response.serverError().entity(exception.getMessage()).build(); | ||
}; | ||
} | ||
|
||
private static String formatErrorMessage(JsonProcessingException e, String message) | ||
{ | ||
return "%s: %s at location %s".formatted(message, e.getOriginalMessage(), e.getLocation()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.