I'd recommend you avoid returning Map directly and wrap it inside custom JAXB bean, Otherwise you need to add XmlJavaTypeAdaper. May be Jackson can handle Map directly - not sure about it Cheers, Sergey
On Tue, Jun 14, 2011 at 5:17 PM, Pankaj Jangid <[email protected]> wrote: > I am new to CXF. > I want to GET result as JSON. My getCustomer() resource method is like this > > @Path("/") > @Produces("application/json,application/xml") > public class Service > { > @GET > @Path("/getCustomers") > public String getCustomers() { > HashMap hm = new HashMap(); > hm.put("Hello", "World"); > return hm; > } > > my bean.xml (which is referenced in web.xml is > > <beans xmlns="http://www.springframework.org/schema/beans" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xmlns:jaxrs="http://cxf.apache.org/jaxrs" > xsi:schemaLocation=" > http://www.springframework.org/schema/beans > http://www.springframework.org/schema/beans/spring-beans.xsd > http://cxf.apache.org/jaxrs > http://cxf.apache.org/schemas/jaxrs.xsd"> > > <import resource="classpath:META-INF/cxf/cxf.xml" /> > <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> > > <jaxrs:server id="rest-api" address="/myservice"> > <jaxrs:serviceBeans> > <ref bean="serviceBean"/> > </jaxrs:serviceBeans> > <jaxrs:extensionMappings> > <entry key="json" value="application/json"/> > <entry key="xml" value="application/xml"/> > </jaxrs:extensionMappings> > <jaxrs:providers> > <ref bean="jaxbProvider"/> > <ref bean="jsonProvider"/> > </jaxrs:providers> > </jaxrs:server> > > <bean id="serviceBean" > class="my.Service"/> > <bean id="jaxbProvider" > class="org.apache.cxf.jaxrs.provider.JAXBElementProvider"/> > <bean id="jsonProvider" > class="org.apache.cxf.jaxrs.provider.JSONProvider"/> > > </beans> > > When I access the service it produces this message:- > > No message body writer has been found for response class HashMap. > > -- > Regards > Pankaj >
