Class ErrorEntityWriter<T,​U>

  • Type Parameters:
    T - The entity type to handle
    U - The response type to produce
    All Implemented Interfaces:
    jakarta.ws.rs.ext.MessageBodyWriter<T>

    public abstract class ErrorEntityWriter<T,​U>
    extends Object
    implements jakarta.ws.rs.ext.MessageBodyWriter<T>
    This class allows producing non-JSON responses for particular entities. For example, register a instance with the ErrorMessage entity and the TEXT_HTML MediaType to produce custom HTML error messages.
    • Constructor Detail

      • ErrorEntityWriter

        protected ErrorEntityWriter​(jakarta.ws.rs.core.MediaType contentType,
                                    Class<U> representation)
        Parameters:
        contentType - Content type the writer will produce
        representation - Response type the writer will produce
    • Method Detail

      • isWriteable

        public boolean isWriteable​(Class<?> type,
                                   Type genericType,
                                   Annotation[] annotations,
                                   jakarta.ws.rs.core.MediaType mediaType)
        Specified by:
        isWriteable in interface jakarta.ws.rs.ext.MessageBodyWriter<T>
      • getSize

        public long getSize​(T entity,
                            Class<?> type,
                            Type genericType,
                            Annotation[] annotations,
                            jakarta.ws.rs.core.MediaType mediaType)
        Specified by:
        getSize in interface jakarta.ws.rs.ext.MessageBodyWriter<T>
      • writeTo

        public void writeTo​(T entity,
                            Class<?> type,
                            Type genericType,
                            Annotation[] annotations,
                            jakarta.ws.rs.core.MediaType mediaType,
                            jakarta.ws.rs.core.MultivaluedMap<String,​Object> responseHeaders,
                            OutputStream entityStream)
                     throws IOException,
                            jakarta.ws.rs.WebApplicationException
        Specified by:
        writeTo in interface jakarta.ws.rs.ext.MessageBodyWriter<T>
        Throws:
        IOException
        jakarta.ws.rs.WebApplicationException
      • getRepresentation

        protected abstract U getRepresentation​(T entity)