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


Java JsonWriter.setSerializeNulls方法代码示例

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


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

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

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

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


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