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


Java JsonWriter.of方法代码示例

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


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

示例1: displayCurrentSessionData

import com.squareup.moshi.JsonWriter; //导入方法依赖的package包/类
private void displayCurrentSessionData(PrintStream writer) {
    Activity activity = activityProvider.getCurrentActivity();
    if (activity instanceof SessionDetailsActivity) {
        try {
            // Use reflection to access private "session" field
            Field field = SessionDetailsActivity.class.getDeclaredField("session");
            field.setAccessible(true);
            Session session = (Session) field.get(activity);

            // Convert sessions to a human readable json
            Buffer buffer = new Buffer();
            JsonWriter jsonWriter = JsonWriter.of(buffer);
            jsonWriter.setIndent("  ");
            moshi.adapter(Session.class).toJson(jsonWriter, session);
            String sessionJson = buffer.readUtf8();

            writer.println(sessionJson);
        } catch (Exception e) {
            writer.println(e.getMessage());
        }
    } else {
        writer.println("SessionDetailsActivity not visible");
    }
}
 
开发者ID:Nilhcem,项目名称:droidconat-2016,代码行数:25,代码来源:AppDumperPlugin.java

示例2: writePackageFile

import com.squareup.moshi.JsonWriter; //导入方法依赖的package包/类
/**
 * Generates a dummy package.json file to silence npm warnings
 */
private void writePackageFile(File apolloPackageFile) {
  try {
    JsonWriter writer = JsonWriter.of(Okio.buffer(Okio.sink(apolloPackageFile)));

    writer.beginObject();

    writer.name("name").value("apollo-android");
    writer.name("version").value("0.0.1");
    writer.name("description").value("Generates Java code based on a GraphQL schema and query documents. Uses " +
        "apollo-codegen under the hood.");
    writer.name("name").value("apollo-android");
    writer.name("repository");
    writer.beginObject();
    writer.name("type").value("git");
    writer.name("url").value("git+https://github.com/apollostack/apollo-android.git");
    writer.endObject();
    writer.name("author").value("Apollo");
    writer.name("license").value("MIT");
    writer.endObject();
    writer.close();
  }
  catch (IOException e) {
    e.printStackTrace();
  }
}
 
开发者ID:apollographql,项目名称:apollo-android,代码行数:29,代码来源:ApolloCodeGenInstallTask.java

示例3: writeConfigurationToFile

import com.squareup.moshi.JsonWriter; //导入方法依赖的package包/类
private void writeConfigurationToFile(HeimdallApplicationConfiguration configuration) {
    try {
        Buffer buffer = new Buffer();
        JsonWriter writer = JsonWriter.of(buffer);
        writer.setSerializeNulls(true);
        writer.setIndent("   ");

        Moshi moshi = new Moshi.Builder().build();
        moshi.adapter(HeimdallApplicationConfiguration.class).toJson(writer, configuration);
        String json = buffer.readUtf8();
        FileUtils.writeStringToFile(new File(HeimdallApplicationConstants.CONFIG_FILE), json);
    } catch (Exception e) {
        log.error("Failed writing configuration to file.",  e);
    }
}
 
开发者ID:thebagchi,项目名称:heimdall-proxy,代码行数:16,代码来源:HeimdallProxyApplication.java

示例4: errorResponseFor

import com.squareup.moshi.JsonWriter; //导入方法依赖的package包/类
@NotNull
private Response errorResponseFor(final Throwable e) {
  Buffer buffer = new Buffer();
  JsonWriter writer = JsonWriter.of(buffer);
  try {
    writer.beginObject();
    writer.name("error").value(e.getMessage());
    writer.endObject();
  } catch (IOException ignored) {
  }
  return Response.newFixedLengthResponse(Status.INTERNAL_ERROR, JSON, buffer.readByteArray());
}
 
开发者ID:strykeforce,项目名称:thirdcoast,代码行数:13,代码来源:TelemetryController.java

示例5: measurementsToJson

import com.squareup.moshi.JsonWriter; //导入方法依赖的package包/类
public void measurementsToJson(BufferedSink sink) throws IOException {
  long ts = System.currentTimeMillis();
  JsonWriter writer = JsonWriter.of(sink);
  writer.beginObject();
  writer.name("timestamp").value(ts);
  writer.name("data");
  writer.beginArray();
  for (DoubleSupplier m : measurements) {
    writer.value(m.getAsDouble());
  }
  writer.endArray();
  writer.endObject();
}
 
开发者ID:strykeforce,项目名称:thirdcoast,代码行数:14,代码来源:Subscription.java

示例6: toJson

import com.squareup.moshi.JsonWriter; //导入方法依赖的package包/类
public void toJson(BufferedSink sink) throws IOException {
  long ts = System.currentTimeMillis();
  JsonWriter writer = JsonWriter.of(sink);
  writer.beginObject();
  writer.name("type").value("subscription");
  writer.name("timestamp").value(ts);
  writer.name("descriptions");
  writer.beginArray();
  for (String d : descriptions) {
    writer.value(d);
  }
  writer.endArray();
  writer.endObject();
}
 
开发者ID:strykeforce,项目名称:thirdcoast,代码行数:15,代码来源:Subscription.java

示例7: writeInventory

import com.squareup.moshi.JsonWriter; //导入方法依赖的package包/类
@Override
public void writeInventory(BufferedSink sink) throws IOException {
  JsonWriter writer = JsonWriter.of(sink);
  writer.setIndent("  ");
  writer.beginObject();
  writer.name("items");
  writeItems(writer);
  writer.name("measures");
  writeMeasures(writer);
  writer.endObject();
}
 
开发者ID:strykeforce,项目名称:thirdcoast,代码行数:12,代码来源:AbstractInventory.java

示例8: toJson

import com.squareup.moshi.JsonWriter; //导入方法依赖的package包/类
@Override
public void toJson(BufferedSink sink) throws IOException {
  JsonWriter writer = JsonWriter.of(sink);
  writer.setIndent("  ");
  writer.beginArray();
  for (Item item : items) {
    item.toJson(writer);
  }
  writer.endArray();
}
 
开发者ID:strykeforce,项目名称:thirdcoast,代码行数:11,代码来源:AbstractInventory.java

示例9: writeIndexMetadata

import com.squareup.moshi.JsonWriter; //导入方法依赖的package包/类
void writeIndexMetadata(String index, String id) throws IOException {
  JsonWriter writer = JsonWriter.of(body);
  writer.beginObject().name("index").beginObject();
  writer.name("_index").value(index);
  writer.name("_type").value(typeName);
  writer.name("_id").value(id);
  writer.endObject().endObject();
  body.writeByte('\n');
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:10,代码来源:HttpBulkIndexer.java

示例10: maintainsPreviousSerializationValue

import com.squareup.moshi.JsonWriter; //导入方法依赖的package包/类
@Test public void maintainsPreviousSerializationValue() throws Exception {
  JsonAdapter<Data1> adapter = moshi.adapter(Data1.class);
  Data1 data1 = new Data1();

  JsonWriter writer1 = JsonWriter.of(new Buffer());
  writer1.setSerializeNulls(true);
  adapter.toJson(writer1, data1);
  assertThat(writer1.getSerializeNulls()).isTrue();

  JsonWriter writer2 = JsonWriter.of(new Buffer());
  writer2.setSerializeNulls(false);
  adapter.toJson(writer2, data1);
  assertThat(writer2.getSerializeNulls()).isFalse();
}
 
开发者ID:serj-lotutovici,项目名称:moshi-lazy-adapters,代码行数:15,代码来源:SerializeNullsJsonAdapterTest.java

示例11: toJson

import com.squareup.moshi.JsonWriter; //导入方法依赖的package包/类
@ToJson
String toJson(GitHubEvent event) {
    Buffer buffer = new Buffer();
    JsonWriter writer = JsonWriter.of(buffer);
    Moshi moshi = ServiceGenerator.moshi;

    try {
        writer.beginObject()
                .name("type").value(event.type().toString())
                .name("ud").value(event.id())
                .name("created_at").value(new FormattedTimeAdapter().toJson(event.createdAt()))
                .name("public").value(event.isPublic() != null ? event.isPublic() : true);
        
        writer.name("org");
        User.jsonAdapter(moshi).toJson(writer, event.org());
        writer.name("actor");
        User.jsonAdapter(moshi).toJson(writer, event.actor());
        writer.name("repo");
        Repository.jsonAdapter(moshi).toJson(writer, event.repo());
        writer.name("payload");
        payloadToJson(event.type(), moshi, event.payload(), writer);

        writer.endObject();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return buffer.toString();
}
 
开发者ID:Meisolsson,项目名称:GitHubSdk,代码行数:30,代码来源:GitHubEventAdapter.java

示例12: convert

import com.squareup.moshi.JsonWriter; //导入方法依赖的package包/类
@Override public RequestBody convert(T value) throws IOException {
  Buffer buffer = new Buffer();
  JsonWriter writer = JsonWriter.of(buffer);
  adapter.toJson(writer, value);
  return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:7,代码来源:MoshiRequestBodyConverter.java


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