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


Java JsonWriter类代码示例

本文整理汇总了Java中com.google.gson.stream.JsonWriter的典型用法代码示例。如果您正苦于以下问题:Java JsonWriter类的具体用法?Java JsonWriter怎么用?Java JsonWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: write

import com.google.gson.stream.JsonWriter; //导入依赖的package包/类
@Override
public void write(JsonWriter out, Object value) throws IOException {
    if (value == null) {
        out.nullValue();
        return;
    }

    TypeAdapter<Object> typeAdapter = (TypeAdapter<Object>) gson.getAdapter(value.getClass());
    if (typeAdapter instanceof NumberPredictObjectTypeAdapter) {
        out.beginObject();
        out.endObject();
        return;
    }

    typeAdapter.write(out, value);
}
 
开发者ID:EntryPointKR,项目名称:MCLibrary,代码行数:17,代码来源:NumberPredictObjectTypeAdapterFactory.java

示例2: saveToWriter

import com.google.gson.stream.JsonWriter; //导入依赖的package包/类
public static void saveToWriter(Collection<? extends Record> records, Writer writer) throws IOException {
    JsonWriter jsonWriter = new JsonWriter(writer);
    jsonWriter.beginArray();
    for (Record record : records) {
        jsonWriter.beginObject();
        jsonWriter.name(ALGORITHM_ID).value(record.getAlgorithmId());
        jsonWriter.name(DATASET_ID).value(record.getDatasetId());
        jsonWriter.name(MEASUREMENT_METHOD).value(record.getMeasurementMethod());
        jsonWriter.name(MEASUREMENT_AUTHOR).value(record.getMeasurementAuthor());
        jsonWriter.name(MEASUREMENT_TIME).value(record.getMeasurementTime().toString());
        jsonWriter.name(CPU_MODEL_NAME).value(record.getCpuModelName());
        jsonWriter.name(JAVA_RUNTIME_VERSION).value(record.getJavaRuntimeVersion());
        jsonWriter.name(MEASUREMENTS).beginArray();
        for (double measurement : record.getMeasurements()) {
            jsonWriter.value(measurement);
        }
        jsonWriter.endArray();
        jsonWriter.name(COMMENT).value(record.getComment());
        jsonWriter.endObject();
    }
    jsonWriter.endArray();
}
 
开发者ID:mbuzdalov,项目名称:non-dominated-sorting,代码行数:23,代码来源:Records.java

示例3: gatherParsers

import com.google.gson.stream.JsonWriter; //导入依赖的package包/类
@Override
public void gatherParsers(GsonBuilder builder) {
    builder.registerTypeHierarchyAdapter(TrickType.class, new TypeAdapter<TrickType>() {
        @Override
        public TrickType read(JsonReader in) throws IOException {
            TrickType type =  TrickType.byId.get(in.nextString());
            if (type == null) {
                return TrickType.STRING;
            }
            return type;
        }
        
        @Override
        public void write(JsonWriter out, TrickType value) throws IOException {
            out.value(value.getId());
        }
    });
}
 
开发者ID:tterrag1098,项目名称:MCBot,代码行数:19,代码来源:CommandTrick.java

示例4: doubleAdapter

import com.google.gson.stream.JsonWriter; //导入依赖的package包/类
private TypeAdapter<Number> doubleAdapter(boolean serializeSpecialFloatingPointValues) {
  if (serializeSpecialFloatingPointValues) {
    return TypeAdapters.DOUBLE;
  }
  return new TypeAdapter<Number>() {
    @Override public Double read(JsonReader in) throws IOException {
      if (in.peek() == JsonToken.NULL) {
        in.nextNull();
        return null;
      }
      return in.nextDouble();
    }
    @Override public void write(JsonWriter out, Number value) throws IOException {
      if (value == null) {
        out.nullValue();
        return;
      }
      double doubleValue = value.doubleValue();
      checkValidFloatingPoint(doubleValue);
      out.value(value);
    }
  };
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:Gson.java

示例5: toJSONString

import com.google.gson.stream.JsonWriter; //导入依赖的package包/类
/**
 * Serialize this fancy message, converting it into syntactically-valid JSON using a {@link JsonWriter}.
 * This JSON should be compatible with vanilla formatter commands such as {@code /tellraw}.
 *
 * @return The JSON string representing this object.
 */
public String toJSONString() {
	if (!dirty && jsonString != null) {
		return jsonString;
	}
	StringWriter string = new StringWriter();
	JsonWriter json = new JsonWriter(string);
	try {
		writeJson(json);
		json.close();
	} catch (IOException e) {
		throw new RuntimeException("invalid message");
	}
	jsonString = string.toString();
	dirty = false;
	return jsonString;
}
 
开发者ID:Slaymd,项目名称:CaulCrafting,代码行数:23,代码来源:FancyMessage.java

示例6: writeJson

import com.google.gson.stream.JsonWriter; //导入依赖的package包/类
@Override
public void writeJson(JsonWriter writer) throws IOException {
	writer.name(getKey());
	writer.beginObject();
	for (Map.Entry<String, String> jsonPair : _value.entrySet()) {
		writer.name(jsonPair.getKey()).value(jsonPair.getValue());
	}
	writer.endObject();
}
 
开发者ID:Chazmondo,项目名称:RankVouchers,代码行数:10,代码来源:TextualComponent.java

示例7: write

import com.google.gson.stream.JsonWriter; //导入依赖的package包/类
@Override public void write(JsonWriter out, T value) throws IOException {
  if (value == null) {
    out.nullValue();
    return;
  }

  out.beginObject();
  try {
    for (BoundField boundField : boundFields.values()) {
      if (boundField.serialized) {
        out.name(boundField.name);
        boundField.write(out, value);
      }
    }
  } catch (IllegalAccessException e) {
    throw new AssertionError();
  }
  out.endObject();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:ReflectiveTypeAdapterFactory.java

示例8: write

import com.google.gson.stream.JsonWriter; //导入依赖的package包/类
@Override
public void write(JsonWriter out, T obj) throws IOException {
    //log("BaseTypeAdapter_write");
    out.beginObject();
    for (GsonProperty prop : mProps) {
        Object val = SupportUtils.getValue(prop, obj);
        if (val == null) {
            continue;
        }
        //gson name
        out.name(prop.getRealSerializeName());

      //  log("simpleType = " + simpleType.getName());
        TypeHandler.getTypeHandler(prop).write(out, prop, val);
    }
    out.endObject();
}
 
开发者ID:LightSun,项目名称:data-mediator,代码行数:18,代码来源:BaseTypeAdapter.java

示例9: write

import com.google.gson.stream.JsonWriter; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override public void write(JsonWriter out, Object value) throws IOException {
  if (value == null) {
    out.nullValue();
    return;
  }

  TypeAdapter<Object> typeAdapter = (TypeAdapter<Object>) gson.getAdapter(value.getClass());
  if (typeAdapter instanceof ObjectTypeAdapter) {
    out.beginObject();
    out.endObject();
    return;
  }

  typeAdapter.write(out, value);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:ObjectTypeAdapter.java

示例10: write

import com.google.gson.stream.JsonWriter; //导入依赖的package包/类
@Override
public void write(JsonWriter out, Calendar value) throws IOException {
  if (value == null) {
    out.nullValue();
    return;
  }
  out.beginObject();
  out.name(YEAR);
  out.value(value.get(Calendar.YEAR));
  out.name(MONTH);
  out.value(value.get(Calendar.MONTH));
  out.name(DAY_OF_MONTH);
  out.value(value.get(Calendar.DAY_OF_MONTH));
  out.name(HOUR_OF_DAY);
  out.value(value.get(Calendar.HOUR_OF_DAY));
  out.name(MINUTE);
  out.value(value.get(Calendar.MINUTE));
  out.name(SECOND);
  out.value(value.get(Calendar.SECOND));
  out.endObject();
}
 
开发者ID:odoo-mobile-intern,项目名称:odoo-work,代码行数:22,代码来源:TypeAdapters.java

示例11: toJson

import com.google.gson.stream.JsonWriter; //导入依赖的package包/类
/**
 * Writes the JSON for {@code jsonElement} to {@code writer}.
 * @throws JsonIOException if there was a problem writing to the writer
 */
public void toJson(JsonElement jsonElement, JsonWriter writer) throws JsonIOException {
  boolean oldLenient = writer.isLenient();
  writer.setLenient(true);
  boolean oldHtmlSafe = writer.isHtmlSafe();
  writer.setHtmlSafe(htmlSafe);
  boolean oldSerializeNulls = writer.getSerializeNulls();
  writer.setSerializeNulls(serializeNulls);
  try {
    Streams.write(jsonElement, writer);
  } catch (IOException e) {
    throw new JsonIOException(e);
  } finally {
    writer.setLenient(oldLenient);
    writer.setHtmlSafe(oldHtmlSafe);
    writer.setSerializeNulls(oldSerializeNulls);
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:Gson.java

示例12: nullSafe

import com.google.gson.stream.JsonWriter; //导入依赖的package包/类
public final TypeAdapter<T> nullSafe() {
    return new TypeAdapter<T>() {
        public void write(JsonWriter out, T value) throws IOException {
            if (value == null) {
                out.nullValue();
            } else {
                TypeAdapter.this.write(out, value);
            }
        }

        public T read(JsonReader reader) throws IOException {
            if (reader.peek() != JsonToken.NULL) {
                return TypeAdapter.this.read(reader);
            }
            reader.nextNull();
            return null;
        }
    };
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:20,代码来源:TypeAdapter.java

示例13: create

import com.google.gson.stream.JsonWriter; //导入依赖的package包/类
@Override
public <R> TypeAdapter<R> create(Gson gson, TypeToken<R> type) {
  if (type.getRawType() != baseType) {
    return null;
  }

  return new TypeAdapter<R>() {
    @Override public R read(JsonReader in) throws IOException {
      JsonElement jsonElement = Streams.parse(in);
      JsonElement labelJsonElement = jsonElement.getAsJsonObject().remove(typeFieldName);
      if (labelJsonElement == null) {
        throw new JsonParseException("cannot deserialize " + baseType
            + " because it does not define a field named " + typeFieldName);
      }
      String label = labelJsonElement.getAsString();
      
      try {
        String subclassName = baseType.getName() + "$" + label.replaceAll("\\s", "");
        Class<?> subclass = Class.forName(subclassName);
        @SuppressWarnings("unchecked")
        TypeAdapter<R> delegate = (TypeAdapter<R>) gson.getDelegateAdapter(
            InnerClassTypeAdapterFactory.this, TypeToken.get(subclass));
        if (delegate == null) {
          throw new JsonParseException("cannot deserialize " + baseType + " subtype named "
              + label);
        }
        return delegate.fromJsonTree(jsonElement);
      } catch (ClassNotFoundException e) {
        throw new JsonParseException("cannot deserialize " + baseType + " subtype named "
            + label);
      }
    }

    @Override public void write(JsonWriter out, R value) throws IOException {
      throw new NotImplementedException("Write not implemented for InnerClassTypeAdapter");
    }
  }.nullSafe();
}
 
开发者ID:synthetichealth,项目名称:synthea_java,代码行数:39,代码来源:InnerClassTypeAdapterFactory.java

示例14: writeJson

import com.google.gson.stream.JsonWriter; //导入依赖的package包/类
@Override
public void writeJson(JsonWriter writer) throws IOException {
	if (messageParts.size() == 1) {
		latest().writeJson(writer);
	} else {
		writer.beginObject().name("text").value("").name("extra").beginArray();
		for (final MessagePart part : this) {
			part.writeJson(writer);
		}
		writer.endArray().endObject();
	}
}
 
开发者ID:Chazmondo,项目名称:RankVouchers,代码行数:13,代码来源:FancyMessage.java

示例15: SaveRecipe

import com.google.gson.stream.JsonWriter; //导入依赖的package包/类
public boolean SaveRecipe(Recipe recipe) {
	String filename = nameService.simplify(recipe.name);
	Path filepath = Paths.get(getRecipesFolder().getPath(), (filename + ".json"));
	try {
		JsonWriter writer = new JsonWriter(new FileWriter(filepath.toFile()));
		gson.toJson(recipe, Recipe.class, writer);
	} catch (JsonIOException | IOException e) {
		logger.error(e.getMessage());
		e.printStackTrace();
		return false;
	}
	return true;
}
 
开发者ID:NMSU-SIC-Club,项目名称:JavaFX_Tutorial,代码行数:14,代码来源:RecipeLoaderService.java


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