You can blame JacksonFeature
JacksonFeature registers the default exception JacksonFeature for Jackson exceptions if JacksonJaxbJsonProvider not registered. And thatβs exactly what you donβt want.
See the relevant parts of the source code :
// Register Jackson. if (!config.isRegistered(JacksonJaxbJsonProvider.class)) { // add the default Jackson exception mappers context.register(JsonParseExceptionMapper.class); context.register(JsonMappingExceptionMapper.class); ... }
Spring Boot registers JacksonFeature
The Spring Boot JerseyAutoConfiguration class JerseyAutoConfiguration register JacksonFeature if it is in the classpath. See the relevant parts of the source code :
@ConditionalOnClass(JacksonFeature.class) @ConditionalOnSingleCandidate(ObjectMapper.class) @Configuration static class JacksonResourceConfigCustomizer { ... @Bean public ResourceConfigCustomizer resourceConfigCustomizer( final ObjectMapper objectMapper) { addJaxbAnnotationIntrospectorIfPresent(objectMapper); return (ResourceConfig config) -> { config.register(JacksonFeature.class); config.register(new ObjectMapperContextResolver(objectMapper), ContextResolver.class); }; } ... }
Bypass
As a workaround, you can register JacksonJaxbJsonProvider and then register your custom display mechanisms (or just annotate them with @Provider to automatically detect Jersey):
@Component public class OrderServiceResourceConfig extends ResourceConfig { public OrderServiceResourceConfig() { packages("com.rmn.gfc.common.providers"); register(JacksonJaxbJsonProvider.class);
See what JacksonJaxbJsonProvider documentation says:
The JSON content type provider is automatically configured to use Jackson and JAXB annotations (in this order of priority). Otherwise, functionally the same as JacksonJsonProvider .
Alternative solution
Alternatively, you can get rid of the jersey-media-json-jackson and use jackson-jaxrs-json-provider . With this, you get rid of JacksonFeature , and then you can register your own display engines.
It was mentioned in this.
What seems like the right decision
As stated in the Kysil Ivan answer , write your own exception display unit and give it a high priority, e.g. 1 . If you use automatic detection, just comment it with @Provider and @Priority :
@Provider @Priority(1) public class JsonParseExceptionMapper implements ExceptionMapper<JsonParseException> { ... }
If you manually register your provider, you can give the provider a binding priority :
@ApplicationPath("/") public class MyResourceConfig extends ResourceConfig { public MyResourceConfig() { register(JsonParseExceptionMapper.class, 1); } }