title: Implementing custom MessageBodyWriter
body: <p>I am getting the following message on the console: </p>
  
  <pre><code>`MessageBodyWriter not found for media type=application/json, type=class java.util.HashMap, genericType=class java.util.HashMap.`
  </code></pre>
  
  <p>on invoking following ReST service:</p>
  
  <pre><code>@GET
  @Path("/m1")
  @Produces(MediaType.APPLICATION_JSON)
  public Map&lt;String, ArrayList&lt;EntityClass&gt;&gt; m1(){
      return new Definition().webMethod1();
  }
  </code></pre>
  
  <p>so I implemented the <code>MessageBodyWriter</code> class as follow:</p>
  
  <pre><code>package web;
  
  import java.io.IOException;
  import java.io.OutputStream;
  import java.lang.annotation.Annotation;
  import java.lang.reflect.Type;
  import java.util.ArrayList;
  import java.util.Map;
  
  import javax.ws.rs.Produces;
  import javax.ws.rs.WebApplicationException;
  import javax.ws.rs.core.MediaType;
  import javax.ws.rs.core.MultivaluedMap;
  import javax.ws.rs.ext.MessageBodyWriter;
  import javax.ws.rs.ext.Provider;
  
  @Provider
  @Produces(MediaType.APPLICATION_JSON)
  public class Writer implements MessageBodyWriter&lt;Map&lt;String, ArrayList&lt;EntityClass&gt;&gt;&gt;{
  
      @Override
      public long getSize(Map&lt;String, ArrayList&lt;EntityClass&gt;&gt; arg0, Class&lt;?&gt; arg1, Type arg2, Annotation[] arg3, MediaType arg4) {
          return arg0.size();
      }
  
      @Override
      public boolean isWriteable(Class&lt;?&gt; arg0, Type arg1, Annotation[] arg2, MediaType arg3) {
          return  arg0 == EntityClass.class;
      }
  
      @Override
      public void writeTo(Map&lt;String, ArrayList&lt;EntityClass&gt;&gt; arg0, Class&lt;?&gt; arg1, Type arg2, Annotation[] arg3,
              MediaType arg4, MultivaluedMap&lt;String, Object&gt; arg5, OutputStream arg6)
              throws IOException, WebApplicationException {
          System.out.println("Exe started..............................................................................");
          StringBuffer sb = new StringBuffer("{");
          ArrayList&lt;EntityClass&gt; entityObj = arg0.get("Entity");
          for(EntityClass eobj: entityObj){
              sb.append("[{");
              sb.append("\"id\":\""+eobj.getId()+"\",");
              sb.append("\"name\":\""+eobj.getName()+"\"");
              sb.append("}],");
          }
          sb.replace(sb.length()-1, sb.length(), "}");
          System.out.println(sb);
          arg6.write(sb.toString().getBytes());
      }
  
  }
  </code></pre>
  
  <p>Still I'm getting same error and no <code>system.out.println</code> line of <code>writeTo</code> method of <code>writer</code> class is shown on the console.</p>
  
  <p>What could be the error and which could be a possible solution?</p>