I am unable to respond with pure JSON using a POJO service. Here is my POJO:
public class AxisTest {
public String getVersion() throws Exception {
return "{ "customer" : { "name" : { "$" : "Jane Doe" } } }";
}
}
The response I get in the browser includes the wrapper:
<ns:getVersionResponse xmlns:ns="http://axisversion.sample">
<ns:return>{ "customer" : { "name" : "Jane Doe", "company" : "Acme
Enterprises"}</ns:return>
</ns:getVersionResponse>
Instead, I would like get back only:
{ "customer" : { "name" : "Jane Doe", "company" : "Acme Enterprises"}
In the browser, I see the content-type showing up as : "application/xml".
I might be able to resolve this problem by setting the content type to
"application/json". How do I set the content type on a POJO service?
Do I need return XML and Axis2 will automatically convert it to JSON (based
on the message formatter setting of JSONMessageFormatter)?
Here is my services.xml:
<service name="AxisTest3" scope="application">
<description>This service is to JSON in Axis.</description>
<parameter name="ServiceClass">sample.axisversion.AxisTest</parameter>
<messageReceivers>
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
class="
org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/>
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
class="
org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
</messageReceivers>
<messageFormatters>
<messageFormatter contentType="application/json" class="
org.apache.axis2.json.JSONMessageFormatter"/>
</messageFormatters>
<messageBuilders>
<messageBuilder contentType="application/json" class="
org.apache.axis2.json.JSONOMBuilder"/>
</messageBuilders>
</service>