moshi如何访问私人领域?

时间:2017-12-01 16:51:52

标签: java android moshi

我有以下模特课:

class Recipe {

  @Json(name = "name") private String mName;

  public String getName() {
    return mName;
  }
}

我正在使用以下代码解析Json:

private static final JsonAdapter<List<Recipe>> recipeListAdapter = moshi.adapter(
      Types.newParameterizedType(List.class, Recipe.class));

Flowable.fromCallable(() -> {
      Request request = new Request.Builder()
          .url(URL)
          .build();
      try (Response response = client.newCall(request).execute()) {
        if (!response.isSuccessful()) {
          throw new IOException("Unexpected code " + response);
        }
        return recipeListAdapter.fromJson(response.body().source());
      }
    })
        .subscribeOn(Schedulers.newThread())
        .observeOn(AndroidSchedulers.
        .subscribe(recipes -> {
          Log.i(TAG, recipes.get(0).getName() + "");
        }, Throwable::printStackTrace);

所以在这里我可以设置私有字段,即使它是私有的,也没有setter。

这怎么可能? moshi如何设置私人领域?

0 个答案:

没有答案