當前位置: 首頁>>代碼示例>>Java>>正文


Java MoshiConverterFactory.create方法代碼示例

本文整理匯總了Java中retrofit2.converter.moshi.MoshiConverterFactory.create方法的典型用法代碼示例。如果您正苦於以下問題:Java MoshiConverterFactory.create方法的具體用法?Java MoshiConverterFactory.create怎麽用?Java MoshiConverterFactory.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在retrofit2.converter.moshi.MoshiConverterFactory的用法示例。


在下文中一共展示了MoshiConverterFactory.create方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: API

import retrofit2.converter.moshi.MoshiConverterFactory; //導入方法依賴的package包/類
API(Context context, Level apiLevel) {
    this.apiLevel = apiLevel;
    final Moshi moshi = new Moshi.Builder()
            .add(Folder.class, new FolderTypeAdapter())
            .add(Feed.class, new FeedTypeAdapter())
            .add(Item.class, new ItemTypeAdapter())
            .add(User.class, new UserTypeAdapter())
            .add(Status.class, new StatusTypeAdapter())
            .build();

    converterFactory = MoshiConverterFactory.create(moshi);

    errorJsonAdapter = moshi.adapter(NewsError.class);

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    String username = Preferences.USERNAME.getString(sharedPreferences);
    if (username != null) {
        String password = Preferences.PASSWORD.getString(sharedPreferences);
        String url = Preferences.URL.getString(sharedPreferences);
        setupApi(new HttpManager(username, password, HttpUrl.parse(url)));
    }
}
 
開發者ID:schaal,項目名稱:ocreader,代碼行數:23,代碼來源:API.java

示例2: main

import retrofit2.converter.moshi.MoshiConverterFactory; //導入方法依賴的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

示例3: provideMoshiConverterFactory

import retrofit2.converter.moshi.MoshiConverterFactory; //導入方法依賴的package包/類
@Provides
@Singleton
MoshiConverterFactory provideMoshiConverterFactory() {
    return MoshiConverterFactory.create();
}
 
開發者ID:VDenis,項目名稱:YandexTranslator,代碼行數:6,代碼來源:ModelModule.java

示例4: converterFactory

import retrofit2.converter.moshi.MoshiConverterFactory; //導入方法依賴的package包/類
@Provides
@Singleton
Converter.Factory converterFactory() {
  return MoshiConverterFactory.create();
}
 
開發者ID:mkjensen,項目名稱:danish-media-license,代碼行數:6,代碼來源:BackendModule.java

示例5: provideTmdbResponseConverterFactory

import retrofit2.converter.moshi.MoshiConverterFactory; //導入方法依賴的package包/類
@Provides @Singleton @Named("Movie Converter")
public Converter.Factory provideTmdbResponseConverterFactory(Moshi moshi){
    return new TmdbResultsResponseConverterFactory(MoshiConverterFactory.create(moshi));
}
 
開發者ID:Rashwan,項目名稱:Reactive-Popular-Movies,代碼行數:5,代碼來源:ApplicationModule.java

示例6: provideTmdbCastResponseConverterFactory

import retrofit2.converter.moshi.MoshiConverterFactory; //導入方法依賴的package包/類
@Provides @Singleton @Named("Cast Converter")
public Converter.Factory provideTmdbCastResponseConverterFactory(Moshi moshi){
    return new TmdbCastResponseConverterFactory(MoshiConverterFactory.create(moshi));
}
 
開發者ID:Rashwan,項目名稱:Reactive-Popular-Movies,代碼行數:5,代碼來源:ApplicationModule.java


注:本文中的retrofit2.converter.moshi.MoshiConverterFactory.create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。