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


Java Moshi.adapter方法代码示例

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


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

示例1: writeTranslationList

import com.squareup.moshi.Moshi; //导入方法依赖的package包/类
void writeTranslationList(TranslationList list) {
  File cacheFile = getCachedFile();
  try {
    File directory = cacheFile.getParentFile();
    boolean directoryExists = directory.mkdirs() || directory.isDirectory();
    if (directoryExists) {
      if (cacheFile.exists()) {
        cacheFile.delete();
      }
      Moshi moshi = new Moshi.Builder().build();
      JsonAdapter<TranslationList> jsonAdapter = moshi.adapter(TranslationList.class);
      BufferedSink sink = Okio.buffer(Okio.sink(cacheFile));
      jsonAdapter.toJson(sink, list);
      sink.close();
      quranSettings.setLastUpdatedTranslationDate(System.currentTimeMillis());
    }
  } catch (Exception e) {
    cacheFile.delete();
    Crashlytics.logException(e);
  }
}
 
开发者ID:Elias33,项目名称:Quran,代码行数:22,代码来源:TranslationManagerPresenter.java

示例2: API

import com.squareup.moshi.Moshi; //导入方法依赖的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

示例3: getFavorites

import com.squareup.moshi.Moshi; //导入方法依赖的package包/类
public List<Movie> getFavorites() throws IOException
{
    Map<String, ?> allEntries = pref.getAll();
    ArrayList<Movie> movies = new ArrayList<>(24);
    Moshi moshi = new Moshi.Builder().build();

    for (Map.Entry<String, ?> entry : allEntries.entrySet())
    {
        String movieJson = pref.getString(entry.getKey(), null);

        if (!TextUtils.isEmpty(movieJson))
        {
            JsonAdapter<Movie> jsonAdapter = moshi.adapter(Movie.class);

            Movie movie = jsonAdapter.fromJson(movieJson);
            movies.add(movie);
        } else
        {
            // Do nothing;
        }
    }
    return movies;
}
 
开发者ID:rohanoid5,项目名称:CineBuff,代码行数:24,代码来源:FavoritesStore.java

示例4: getDocumentAdapter

import com.squareup.moshi.Moshi; //导入方法依赖的package包/类
public <T extends ResourceIdentifier> JsonAdapter<Document<T>> getDocumentAdapter(Class<T> typeParameter,
                                                                                  Class<? extends Resource>... knownTypes) {
    Moshi moshi;
    if (typeParameter == null) {
        return (JsonAdapter) TestUtil.moshi(knownTypes).adapter(Document.class);
    } else if (typeParameter.getAnnotation(JsonApi.class) != null) {
        Class<? extends Resource>[] types = new Class[knownTypes.length + 1];
        types[0] = (Class) typeParameter;
        for (int i = 0; i != knownTypes.length; i++) {
            types[i + 1] = knownTypes[i];
        }
        moshi = TestUtil.moshi(types);
    } else {
        moshi = TestUtil.moshi(knownTypes);
    }
    return moshi.adapter(Types.newParameterizedType(Document.class, typeParameter));
}
 
开发者ID:kamikat,项目名称:moshi-jsonapi,代码行数:18,代码来源:DocumentTest.java

示例5: IftttApiClient

import com.squareup.moshi.Moshi; //导入方法依赖的package包/类
private IftttApiClient() {
    Moshi moshi = new Moshi.Builder().add(new HexColorJsonAdapter())
            .add(Date.class, new Rfc3339DateJsonAdapter().nullSafe())
            .add(new AppletJsonAdapter())
            .add(new AppletListJsonAdapter())
            .build();
    JsonAdapter<ErrorResponse> errorResponseJsonAdapter = moshi.adapter(ErrorResponse.class);

    tokenInterceptor = new TokenInterceptor();
    inviteCodeInterceptor = new InviteCodeInterceptor();
    OkHttpClient okHttpClient = new OkHttpClient.Builder().addInterceptor(tokenInterceptor)
            .addInterceptor(inviteCodeInterceptor)
            .addInterceptor(new SdkInfoInterceptor())
            .build();
    Retrofit retrofit = new Retrofit.Builder().addConverterFactory(MoshiConverterFactory.create(moshi))
            .baseUrl("https://api.ifttt.com")
            .client(okHttpClient)
            .build();

    RetrofitAppletConfigApi retrofitAppletConfigApi = retrofit.create(RetrofitAppletConfigApi.class);
    appletConfigApi = new InternalAppletConfigApi(retrofitAppletConfigApi, errorResponseJsonAdapter);

    RetrofitAppletsApi retrofitAppletsApi = retrofit.create(RetrofitAppletsApi.class);
    appletsApi = new InternalAppletsApi(retrofitAppletsApi, errorResponseJsonAdapter);

    RetrofitUserApi retrofitUserApi = retrofit.create(RetrofitUserApi.class);
    userApi = new InternalUserApi(retrofitUserApi, errorResponseJsonAdapter);
}
 
开发者ID:IFTTT,项目名称:IFTTTSDK-Android,代码行数:29,代码来源:IftttApiClient.java

示例6: setUp

import com.squareup.moshi.Moshi; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
    Moshi moshi = new Moshi.Builder().add(Date.class, new Rfc3339DateJsonAdapter().nullSafe())
            .add(new TestHexColorJsonAdapter())
            .add(new AppletJsonAdapter())
            .build();
    adapter = moshi.adapter(Applet.class);
}
 
开发者ID:IFTTT,项目名称:IFTTTSDK-Android,代码行数:9,代码来源:AppletTest.java

示例7: loadConfigurationFromFile

import com.squareup.moshi.Moshi; //导入方法依赖的package包/类
private void loadConfigurationFromFile() {
    try {
        String json = FileUtils.readFileToString(new File(HeimdallApplicationConstants.CONFIG_FILE));
        Moshi moshi = new Moshi.Builder().build();
        JsonAdapter<HeimdallApplicationConfiguration> adaper =
                moshi.adapter(HeimdallApplicationConfiguration.class);
        configuration = adaper.fromJson(json);
    } catch (Exception e) {
        log.error("Failed loading configuration from file.",  e);
    }
}
 
开发者ID:thebagchi,项目名称:heimdall-proxy,代码行数:12,代码来源:HeimdallProxyApplication.java

示例8: setFavorite

import com.squareup.moshi.Moshi; //导入方法依赖的package包/类
public void setFavorite(Movie movie)
{
    SharedPreferences.Editor editor = pref.edit();
    Moshi moshi = new Moshi.Builder().build();
    JsonAdapter<Movie> jsonAdapter = moshi.adapter(Movie.class);
    String movieJson = jsonAdapter.toJson(movie);
    editor.putString(movie.getId(), movieJson);
    editor.apply();
}
 
开发者ID:rohanoid5,项目名称:CineBuff,代码行数:10,代码来源:FavoritesStore.java

示例9: deserialize_object_to_object_typed_document

import com.squareup.moshi.Moshi; //导入方法依赖的package包/类
@Test
public void deserialize_object_to_object_typed_document() throws Exception {
    Moshi moshi = TestUtil.moshi(Article.class);
    JsonAdapter<?> adapter = moshi.adapter(Types.newParameterizedType(ObjectDocument.class, Article.class));
    assertThat(adapter, instanceOf(ResourceAdapterFactory.DocumentAdapter.class));
    ObjectDocument<Article> objectDocument = ((ObjectDocument<Article>) adapter.fromJson(TestUtil.fromResource("/single.json")));
    assertThat(objectDocument, instanceOf(ObjectDocument.class));
    assertOnArticle1(objectDocument.asObjectDocument().get());
}
 
开发者ID:kamikat,项目名称:moshi-jsonapi,代码行数:10,代码来源:DocumentTest.java

示例10: prepareRouteResponse

import com.squareup.moshi.Moshi; //导入方法依赖的package包/类
private RouteResponse prepareRouteResponse() {
	String json = new TestHelper().getTextContentFromResourcesFile("data.json");
	Moshi moshi = new Moshi.Builder().build();
	JsonAdapter<RouteResponse> jsonAdapter = moshi.adapter(RouteResponse.class);
	try {
		return jsonAdapter.fromJson(json);
	} catch (IOException e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:Zlate87,项目名称:sample-transport-app,代码行数:11,代码来源:ViewModelMappingServiceTest.java

示例11: onCreate

import com.squareup.moshi.Moshi; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mTransaction = null;
    if (savedInstanceState == null) {
        try {
            Moshi moshi = new Moshi.Builder()
                    .add(new JsonDateAdapter())
                    .add(MyAdapterFactory.create())
                    .build();
            InputStream inputStream = getResources().openRawResource(R.raw.data);
            Source source = Okio.source(inputStream);
            BufferedSource bufferedSource = Okio.buffer(source);
            String json = bufferedSource.readUtf8();
            Log.d("AutoValue", "Raw JSON: " + json);
            JsonAdapter<Transaction> transactionJsonAdapter = moshi.adapter(Transaction.class);
            mTransaction = transactionJsonAdapter.fromJson(json);
        } catch (IOException e) {
            Log.e("AutoValue", "Error parsing JSON!", e);
        }
    } else {
        mTransaction = savedInstanceState.getParcelable("transaction");
    }

    Log.d("AutoValue", "Read: " + mTransaction);
}
 
开发者ID:ErikHellman,项目名称:AutoValueDemo,代码行数:29,代码来源:MainActivity.java

示例12: deserializeJson

import com.squareup.moshi.Moshi; //导入方法依赖的package包/类
/**
 * Method that will deserialize a JSON string into {@code RouteResponse}.
 *
 * @param routeResponseJson the JSON string
 * @return the deserialized {@code RouteResponse}
 *
 * @throws RuntimeException if there is a problem with the deserialization of the JSON.
 */
protected RouteResponse deserializeJson(String routeResponseJson) {
	Moshi moshi = new Moshi.Builder().build();
	JsonAdapter<RouteResponse> jsonAdapter = moshi.adapter(RouteResponse.class);
	try {
		return jsonAdapter.fromJson(routeResponseJson);
	} catch (IOException e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:Zlate87,项目名称:sample-transport-app,代码行数:18,代码来源:AbstractJsonRoutingServer.java

示例13: BookmarkJsonModel

import com.squareup.moshi.Moshi; //导入方法依赖的package包/类
@Inject
BookmarkJsonModel() {
  Moshi moshi = new Moshi.Builder().build();
  jsonAdapter = moshi.adapter(BookmarkData.class);
}
 
开发者ID:Elias33,项目名称:Quran,代码行数:6,代码来源:BookmarkJsonModel.java

示例14: newRealmListAdapter

import com.squareup.moshi.Moshi; //导入方法依赖的package包/类
private static <T extends RealmObject> JsonAdapter<RealmList<T>> newRealmListAdapter(Type type, Moshi moshi) {
    Type elementType = Types.collectionElementType(type, RealmList.class);
    JsonAdapter<T> elementAdapter = moshi.adapter(elementType);
    return new RealmListAdapter<>(elementAdapter);
}
 
开发者ID:Commit451,项目名称:Regalia,代码行数:6,代码来源:RealmListJsonAdapterFactory.java

示例15: fromJson

import com.squareup.moshi.Moshi; //导入方法依赖的package包/类
public static RequestJson fromJson(final String json) throws IOException {
  // TODO: verify type=start
  Moshi moshi = new Moshi.Builder().build();
  JsonAdapter<RequestJson> adapter = moshi.adapter(RequestJson.class);
  return adapter.fromJson(json);
}
 
开发者ID:strykeforce,项目名称:thirdcoast,代码行数:7,代码来源:Subscription.java


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