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


Java JsonWriter.name方法代码示例

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


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

示例1: 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

示例2: toJson

import com.squareup.moshi.JsonWriter; //导入方法依赖的package包/类
/**
 * Recursively writes the respective roots forming a json object that resembles the {@code path}
 * wrapping the type of the {@code adapter}.
 */
private static <T> void toJson(JsonAdapter<T> adapter, JsonWriter writer, T value,
    String[] path, int index) throws IOException {
  if (value != null || writer.getSerializeNulls()) {
    if (index == path.length) {
      adapter.toJson(writer, value);
    } else {
      writer.beginObject();
      writer.name(path[index]);
      toJson(adapter, writer, value, path, ++index);
      writer.endObject();
    }
  } else {
    // If we don't propagate the null value the writer will throw.
    writer.nullValue();
  }
}
 
开发者ID:serj-lotutovici,项目名称:moshi-lazy-adapters,代码行数:21,代码来源:WrappedJsonAdapter.java

示例3: 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

示例4: 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

示例5: 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

示例6: writeDeviceMeasures

import com.squareup.moshi.JsonWriter; //导入方法依赖的package包/类
void writeDeviceMeasures(JsonWriter writer, String type, Set<Measure> measures)
    throws IOException {
  writer.beginObject();
  writer.name("deviceType").value(type);
  writer.name("deviceMeasures");
  writer.beginArray();
  for (Measure m : measures) {
    writeMeasure(writer, m);
  }
  writer.endArray();
  writer.endObject();
}
 
开发者ID:strykeforce,项目名称:thirdcoast,代码行数:13,代码来源:AbstractInventory.java

示例7: toJson

import com.squareup.moshi.JsonWriter; //导入方法依赖的package包/类
@Override
public void toJson(JsonWriter out, Feed feed) throws IOException {
    out.beginObject();

    // Only write url for feeds that are not in the database
    if(!RealmObject.isManaged(feed)) {
        out.name("url");
        out.value(feed.getUrl());
    }

    out.name("folderId");
    out.value(feed.getFolderId());

    out.endObject();
}
 
开发者ID:schaal,项目名称:ocreader,代码行数:16,代码来源:FeedTypeAdapter.java

示例8: toJson

import com.squareup.moshi.JsonWriter; //导入方法依赖的package包/类
@Override
public void toJson(JsonWriter writer, HasMany<T> value) throws IOException {
    writer.beginObject();
    writer.name("data");
    writer.beginArray();
    for (ResourceIdentifier resource : value.linkedResources) {
        resourceIdentifierJsonAdapter.toJson(writer, resource);
    }
    writer.endArray();
    writeNullable(writer, jsonBufferJsonAdapter, "meta", value.getMeta());
    writeNullable(writer, jsonBufferJsonAdapter, "links", value.getLinks());
    writer.endObject();
}
 
开发者ID:kamikat,项目名称:moshi-jsonapi,代码行数:14,代码来源:HasMany.java

示例9: 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

示例10: dump

import com.squareup.moshi.JsonWriter; //导入方法依赖的package包/类
public static void dump(JsonReader reader, JsonWriter writer) throws IOException {
    int nested = 0;
    boolean nullFlag = writer.getSerializeNulls();
    writer.setSerializeNulls(true);
    try {
        while (reader.peek() != JsonReader.Token.END_DOCUMENT) {
            switch (reader.peek()) {
                case BEGIN_ARRAY:
                    nested++;
                    reader.beginArray();
                    writer.beginArray();
                    break;
                case END_ARRAY:
                    reader.endArray();
                    writer.endArray();
                    if (0 == --nested) return;
                    break;
                case BEGIN_OBJECT:
                    nested++;
                    reader.beginObject();
                    writer.beginObject();
                    break;
                case END_OBJECT:
                    reader.endObject();
                    writer.endObject();
                    if (0 == --nested) return;
                    break;
                case NAME:
                    writer.name(reader.nextName());
                    break;
                case NUMBER:
                    try {
                        writer.value(reader.nextLong());
                    } catch (Exception ignored) {
                        writer.value(reader.nextDouble());
                    }
                    break;
                case BOOLEAN:
                    writer.value(reader.nextBoolean());
                    break;
                case STRING:
                    writer.value(reader.nextString());
                    break;
                case NULL:
                    reader.nextNull();
                    writer.nullValue();
                    break;
            }
        }
    } finally {
        writer.setSerializeNulls(nullFlag);
    }
}
 
开发者ID:kamikat,项目名称:moshi-jsonapi,代码行数:54,代码来源:MoshiHelper.java

示例11: writeNullable

import com.squareup.moshi.JsonWriter; //导入方法依赖的package包/类
public static <T> void writeNullable(JsonWriter writer, JsonAdapter<T> valueAdapter, String name, T value) throws IOException {
    writer.name(name);
    writeNullableValue(writer, valueAdapter, value);
}
 
开发者ID:kamikat,项目名称:moshi-jsonapi,代码行数:5,代码来源:MoshiHelper.java


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