Unable to marshal type "java.util.HashMap" while hitting the resource with json
<p>I have written a RESTful resource method which produces <code>application/json</code> and <code>application/xml</code> which is defined at class level and below is my method:</p>

<pre><code>@GET
@Path("testing/getNames")
public Map&lt;Long, String&gt; getNames(@QueryParam("list") List&lt;Long&gt; list) {
    // return invoking ejb method and return map            
}
</code></pre>

<p>When i hit this resource with json produces, it's giving the response back but for format=format.xml i am getting the following exception:</p>

<pre><code>Caused by: javax.xml.bind.MarshalException   
 - with linked exception:   
[com.sun.istack.SAXException2: unable to marshal type "java.util.HashMap" as an element because it is missing an @XmlRootElement annotation]  
        at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:326)   
        at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:251)  
        at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:110)  
        at org.glassfish.jersey.jaxb.internal.AbstractRootElementJaxbProvider.writeTo(AbstractRootElementJaxbProvider.java:190)  
        at org.glassfish.jersey.jaxb.internal.AbstractRootElementJaxbProvider.writeTo(AbstractRootElementJaxbProvider.java:169)
        ... 81 more
Caused by: com.sun.istack.SAXException2: unable to marshal type "java.util.HashMap" as an element because it is missing an @XmlRootElement annotation
        at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:249)
        at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:338)
        at com.sun.xml.bind.v2.runtime.property.ArrayReferenceNodeProperty.serializeListBody(ArrayReferenceNodeProperty.java:118)
        at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:159)
        at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:360)
        at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:593)
        at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:341)
        at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:494)
        at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:323)
</code></pre>

<p>Any suggestion on this?</p>