title: How to create a MessageBodyWriter to return a custom object as HTML in RestEasy?
body: <p>I'm using RestEasy together with Spring in Tomcat. I have a simple controller method which I want to use via Ajax (with JSON or XML response) and via a standard browser request (Using HTML as a response). It works when I use simple return data types like a string but I need to return a custom object:</p>
  
  <pre><code>@POST
  @Path("fooBar")
  public RequestResult fooBar()
  {
      return new RequestResult();
  }
  </code></pre>
  
  <p>This is the RequestResult object (Just a dummy implementation for demonstration):</p>
  
  <pre><code>@XmlRootElement(name = "result")
  public final class RequestResult
  {
      @XmlAttribute
      public boolean getWhatever()
      {
          return "whatever";
      }
  }
  </code></pre>
  
  <p>It works when requesting it as JSON or XML but when requesting it as HTML I get the error message <code>Could not find JAXBContextFinder for media type: text/html</code>. It's clear that it can't work because RestEasy doesn't know how to convert this object to HTML. So I added this test MessageBodyWriter:</p>
  
  <pre><code>@Provider
  @Produces("text/html")
  public class ResultProvider implements MessageBodyWriter&lt;RequestResult&gt;
  {
      @Override
      public boolean isWriteable(final Class&lt;?&gt; type, final Type genericType,
          final Annotation[] annotations, final MediaType mediaType)
      {
          return true;
      }
  
      @Override
      public long getSize(final RequestResult t, final Class&lt;?&gt; type, final Type genericType,
          final Annotation[] annotations, final MediaType mediaType)
      {
          return 4;
      }
  
      @Override
      public void writeTo(final RequestResult t, final Class&lt;?&gt; type, final Type genericType,
          final Annotation[] annotations, final MediaType mediaType,
          final MultivaluedMap&lt;String, Object&gt; httpHeaders, final OutputStream entityStream)
          throws IOException, WebApplicationException
      {
          final PrintWriter writer = new PrintWriter(entityStream);
          writer.println("Test");
      }
  }
  </code></pre>
  
  <p>But this doesn't change anything. No method of this provider is ever called. I'm not sure if I have to register it somewhere. All other classes are found automatically by classpath scanning so I guess this also happens for providers.</p>
  
  <p>I'm pretty sure I made something wrong or I forgot something. Any hints?</p>