Understanding JAX-RS Providers

[Last Updated: Jul 16, 2017]

An application can extend JAX-RS runtime by implementing one or more interfaces as specified by the JSR-339. We will explore these interfaces shortly.

These implementations may be annotated with @Provider for automatic discovery during scanning phase.

By default a single instance of each provider class is instantiated for each JAX-RS application.

JAX-RS providers are divided into three categories as follows:

Entity Providers

These providers convert message body to Java object and vice-versa. They implement MessageBodyReader and/or MessageBodyWriter.

Jersey (2.25.1) comes with multiple entity providers:

Among above providers, there are standard providers as specified by JSR-339 section 4.2.4.

Message body readers and writers may be annotated with @Consumes and @Produces annotations, to restrict the media types they support. If these annotations are not used then the provider should support all media types.

Context Providers

These providers must implement ContextResolver<T>.

The implementation should supply the context related object of type T. These contexts objects may be accessed by the resource classes and by the other providers.

Exception Mapping Providers

These providers map a checked or runtime exception to an instance of Response. They implement ExceptionMapper<T>.

Other Providers

JSR-339 (chapter 4) specifies above three provider types, but @Provider annotation can be used on other places as seen here.

See Also