title: Apache CXF as Client for restful API - No message body writer has been found for class
body: <p>I'm using Apache CXF to consume one companies Restful API. I'm getting the following error.</p>
  
  <p>Caused by: org.apache.cxf.jaxrs.client.ClientWebApplicationException: org.apache.cxf.interceptor.Fault: .No message body writer has been found for class : class org.codehaus.jettison.json.JSONObject, ContentType : application/json.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public static void main(String[] args) {
          try {
              WebClient client = WebClient.create("https://aboti.securemanaged.com/rest/user");
              client.type(MediaType.APPLICATION_JSON);
              client.accept(MediaType.APPLICATION_JSON);
              JSONObject obj = new JSONObject("{\"Id\":1,\"name\":\"Alice\",\"version\":\"1.0.0\"}");
              System.out.println("Sending" + obj.toString());
              //Response responseData = client.post(obj);
              String responseData = client.post(obj, String.class);
              System.out.println("Engine one started: " + responseData);
          } catch (JSONException e) {
              e.printStackTrace();
          }
  
      }
  </code></pre>
  
  <p>But when I do curl I"m getting a valid JSON Response as follows:</p>
  
  <pre><code>curl "https://aboti.securemanaged.com/rest/user" -X POST -d '{"Id":1,"name":"Alice","version":"1.0.0"}'
  
  {"trackingId":1564,"statusCode":"registered","status":"1"}
  </code></pre>
  
  <p>I tried to add a default Provider in my dispatcher servlet as follows:
  But am not sure how can I configure the WebClient instance to use this default provider.. or is that not the issue?</p>
  
  <pre><code>  &lt;jaxrs:client id="serviceId" serviceClass="" address="https://aboti.securemanaged.com/rest/user"&gt;
        &lt;jaxrs:providers&gt;
            &lt;bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"&gt;
                &lt;property name="mapper" ref="jacksonMapper" /&gt;
            &lt;/bean&gt;
        &lt;/jaxrs:providers&gt;
    &lt;/jaxrs:client&gt;
    &lt;bean id="jacksonMapper" class="org.codehaus.jackson.map.ObjectMapper"/&gt;
    &lt;bean id="jacksonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" /&gt;
  </code></pre>