本文整理匯總了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)));
}
}
示例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();
}
示例3: provideMoshiConverterFactory
import retrofit2.converter.moshi.MoshiConverterFactory; //導入方法依賴的package包/類
@Provides
@Singleton
MoshiConverterFactory provideMoshiConverterFactory() {
return MoshiConverterFactory.create();
}
示例4: converterFactory
import retrofit2.converter.moshi.MoshiConverterFactory; //導入方法依賴的package包/類
@Provides
@Singleton
Converter.Factory converterFactory() {
return MoshiConverterFactory.create();
}
示例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));
}
示例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));
}