`

CXF-WebClient客户端调用,配置JacksonProvider转换器的方法

 
阅读更多
java语言调用cxf-rest服务,可以通过CXF-WebClient客户端API调用。如果服务器端用了自定义的json转换器,那么客户端调用时也需要相应的json转换器。

如下:



   
  String restBaseUrl="http://localhost:8080/rest/";

          String url="....";

  /**一下两种方式都可以直接转换成对象格式*/
//            List provides=new ArrayList();
//            provides.add(new JacksonJsonProvider());
//            WebClient client = WebClient.create(restBaseUrl,provides);
//            MyResponse resp=client.path(url).query("name", "张三").accept(MediaType.APPLICATION_JSON).get(MyResponse.class);
           
            WebClient client = WebClient.create(restBaseUrl);
            MyResponse resp=client.path(url).query("name", "张三").accept(MediaType.APPLICATION_XML).get(MyResponse.class);
           
            System.out.println(resp);


0
3
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics