---
title: "CXF-WebClient客户端调用，配置JacksonProvider转换器的方法"
author: "井底之蛙"
date: "2012-12-17T11:31:03Z"
tags: []
categories: ["编程语言"]
slug: "cxf-webclient-jacksonprovider"
draft: false
lastmod: "2012-12-17T11:35:06Z"
id: 1748918
url: "https://wellfrog.iteye.com/blog/1748918"
---

**java语言调用cxf-rest服务，可以通过CXF-WebClient客户端API调用。如果服务器端用了自定义的json转换器，那么客户端调用时也需要相应的json转换器。

如下：

**

    
```java
  String restBaseUrl=&quot;http://localhost:8080/rest/&quot;;

          String url=&quot;....&quot;;

  /**一下两种方式都可以直接转换成对象格式*/
//            List provides=new ArrayList();
//            provides.add(new JacksonJsonProvider());
//            WebClient client = WebClient.create(restBaseUrl,provides);
//            MyResponse resp=client.path(url).query(&quot;name&quot;, &quot;张三&quot;).accept(MediaType.APPLICATION_JSON).get(MyResponse.class);
           
            WebClient client = WebClient.create(restBaseUrl);
            MyResponse resp=client.path(url).query(&quot;name&quot;, &quot;张三&quot;).accept(MediaType.APPLICATION_XML).get(MyResponse.class);
           
            System.out.println(resp);
```