In this case we have default and custom (Jackson) application/json providers. The custom one has a higher priority.

For more info see sections 4.2.1 and 4.2.2 of the spec:
https://jcp.org/en/jsr/detail?id=339

Sergey
On 08/05/15 09:09, sanmitra wrote:
The custom provider is preferred by the runtime.
What is the criteria for preference ?

On Thu, May 7, 2015 at 6:11 PM, Sergey Beryozkin [via CXF] <
ml-node+s547215n5757122...@n5.nabble.com> wrote:

On 07/05/15 09:52, sanmitra wrote:

Question 1) To serialize my domain object containing a hashmap, I am
using
org.apache.cxf.jaxrs.provider.json.JSONProvider but getting this error
"No
message body writer has been found for class java.util.HashMap,
ContentType:
application/json". How can I fix this ?

<jaxrs:server id="restContainer" address="/">
          <jaxrs:serviceBeans>
              <ref bean="myService" />
          </jaxrs:serviceBeans>
          <jaxrs:providers>
              <bean id="jsonProvider"
class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
                  <property name="serializeAsArray" value="true" />
              </bean>
          </jaxrs:providers>
      </jaxrs:server>

The default provider only operates on JAXB beans.


Question 2) If I add JacksonProvider in addition to JSONProvider, then
serializing of domain object containing hashmap works fine. My question
here
is when we provide more than one json providers which one does the cxf
container uses ? Is there some preference we can set ?

<jaxrs:server id="restContainer" address="/">
          <jaxrs:serviceBeans>
              <ref bean="myService" />
          </jaxrs:serviceBeans>
          <jaxrs:providers>
              <bean id="jsonProvider"
class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
                  <property name="serializeAsArray" value="true" />
              </bean>
             <bean
class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
          </jaxrs:providers>
      </jaxrs:server>

The custom provider is preferred by the runtime.

Sergey


--
View this message in context:
http://cxf.547215.n5.nabble.com/No-message-body-writer-has-been-found-for-class-java-util-HashMap-tp5757111.html
Sent from the cxf-user mailing list archive at Nabble.com.




------------------------------
  If you reply to this email, your message will be added to the discussion
below:

http://cxf.547215.n5.nabble.com/No-message-body-writer-has-been-found-for-class-java-util-HashMap-tp5757111p5757122.html
  To unsubscribe from No message body writer has been found for class
java.util.HashMap, click here
<http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5757111&code=c2FubWl0cmFqcjBAZ21haWwuY29tfDU3NTcxMTF8LTg1Njk3ODE5OA==>
.
NAML
<http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>





--
View this message in context: 
http://cxf.547215.n5.nabble.com/No-message-body-writer-has-been-found-for-class-java-util-HashMap-tp5757111p5757135.html
Sent from the cxf-user mailing list archive at Nabble.com.


Reply via email to