当前位置: 首页>>代码示例>>Java>>正文


Java SimpleXmlConverterFactory.create方法代码示例

本文整理汇总了Java中retrofit2.converter.simplexml.SimpleXmlConverterFactory.create方法的典型用法代码示例。如果您正苦于以下问题:Java SimpleXmlConverterFactory.create方法的具体用法?Java SimpleXmlConverterFactory.create怎么用?Java SimpleXmlConverterFactory.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在retrofit2.converter.simplexml.SimpleXmlConverterFactory的用法示例。


在下文中一共展示了SimpleXmlConverterFactory.create方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import retrofit2.converter.simplexml.SimpleXmlConverterFactory; //导入方法依赖的package包/类
public static void main(String... args) throws IOException {
  MockWebServer server = new MockWebServer();
  server.start();
  server.enqueue(new MockResponse().setBody("{\"name\": \"Moshi\"}"));
  server.enqueue(new MockResponse().setBody("{\"name\": \"Gson\"}"));
  server.enqueue(new MockResponse().setBody("<user name=\"SimpleXML\"/>"));
  server.enqueue(new MockResponse().setBody("{\"name\": \"Gson\"}"));

  com.squareup.moshi.Moshi moshi = new com.squareup.moshi.Moshi.Builder().build();
  com.google.gson.Gson gson = new GsonBuilder().create();
  MoshiConverterFactory moshiConverterFactory = MoshiConverterFactory.create(moshi);
  GsonConverterFactory gsonConverterFactory = GsonConverterFactory.create(gson);
  SimpleXmlConverterFactory simpleXmlConverterFactory = SimpleXmlConverterFactory.create();
  Retrofit retrofit = new Retrofit.Builder().baseUrl(server.url("/"))
      .addConverterFactory(
          new AnnotatedConverterFactory.Builder().add(Moshi.class, moshiConverterFactory)
              .add(Gson.class, gsonConverterFactory)
              .add(SimpleXml.class, simpleXmlConverterFactory)
              .build())
      .addConverterFactory(gsonConverterFactory)
      .build();
  Service service = retrofit.create(Service.class);

  Library library1 = service.exampleMoshi().execute().body();
  System.out.println("Library 1: " + library1.name);

  Library library2 = service.exampleGson().execute().body();
  System.out.println("Library 2: " + library2.name);

  Library library3 = service.exampleSimpleXml().execute().body();
  System.out.println("Library 3: " + library3.name);

  Library library4 = service.exampleDefault().execute().body();
  System.out.println("Library 4: " + library4.name);

  server.shutdown();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:38,代码来源:AnnotatedConverters.java

示例2: newXmlInstance

import retrofit2.converter.simplexml.SimpleXmlConverterFactory; //导入方法依赖的package包/类
static Converter.Factory newXmlInstance() {
  return SimpleXmlConverterFactory.create();
}
 
开发者ID:cdeange,项目名称:uwaterloo-api,代码行数:4,代码来源:ApiModelConverter.java


注:本文中的retrofit2.converter.simplexml.SimpleXmlConverterFactory.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。