com.google.gson.Gson.newJsonWriter()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(352)

本文整理了Java中com.google.gson.Gson.newJsonWriter()方法的一些代码示例,展示了Gson.newJsonWriter()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Gson.newJsonWriter()方法的具体详情如下:
包路径:com.google.gson.Gson
类名称:Gson
方法名:newJsonWriter

Gson.newJsonWriter介绍

[英]Returns a new JSON writer configured for the settings on this Gson instance.
[中]返回为此Gson实例上的设置配置的新JSON编写器。

代码示例

代码示例来源:origin: square/retrofit

  1. @Override public RequestBody convert(T value) throws IOException {
  2. Buffer buffer = new Buffer();
  3. Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
  4. JsonWriter jsonWriter = gson.newJsonWriter(writer);
  5. adapter.write(jsonWriter, value);
  6. jsonWriter.close();
  7. return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
  8. }
  9. }

代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking

  1. @Override
  2. public RequestBody convert(T value) throws IOException {
  3. Buffer buffer = new Buffer();
  4. Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
  5. JsonWriter jsonWriter = gson.newJsonWriter(writer);
  6. adapter.write(jsonWriter, value);
  7. jsonWriter.close();
  8. return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
  9. }
  10. }

代码示例来源:origin: com.squareup.retrofit2/converter-gson

  1. @Override public RequestBody convert(T value) throws IOException {
  2. Buffer buffer = new Buffer();
  3. Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
  4. JsonWriter jsonWriter = gson.newJsonWriter(writer);
  5. adapter.write(jsonWriter, value);
  6. jsonWriter.close();
  7. return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
  8. }
  9. }

代码示例来源:origin: camunda/camunda-bpm-platform

  1. /**
  2. * Writes out the equivalent JSON for a tree of {@link JsonElement}s.
  3. *
  4. * @param jsonElement root of a tree of {@link JsonElement}s
  5. * @param writer Writer to which the Json representation needs to be written
  6. * @throws JsonIOException if there was a problem writing to the writer
  7. * @since 1.4
  8. */
  9. public void toJson(JsonElement jsonElement, Appendable writer) throws JsonIOException {
  10. try {
  11. JsonWriter jsonWriter = newJsonWriter(Streams.writerForAppendable(writer));
  12. toJson(jsonElement, jsonWriter);
  13. } catch (IOException e) {
  14. throw new JsonIOException(e);
  15. }
  16. }

代码示例来源:origin: camunda/camunda-bpm-platform

  1. /**
  2. * This method serializes the specified object, including those of generic types, into its
  3. * equivalent Json representation. This method must be used if the specified object is a generic
  4. * type. For non-generic objects, use {@link #toJson(Object, Appendable)} instead.
  5. *
  6. * @param src the object for which JSON representation is to be created
  7. * @param typeOfSrc The specific genericized type of src. You can obtain
  8. * this type by using the {@link com.google.gson.reflect.TypeToken} class. For example,
  9. * to get the type for {@code Collection<Foo>}, you should use:
  10. * <pre>
  11. * Type typeOfSrc = new TypeToken&lt;Collection&lt;Foo&gt;&gt;(){}.getType();
  12. * </pre>
  13. * @param writer Writer to which the Json representation of src needs to be written.
  14. * @throws JsonIOException if there was a problem writing to the writer
  15. * @since 1.2
  16. */
  17. public void toJson(Object src, Type typeOfSrc, Appendable writer) throws JsonIOException {
  18. try {
  19. JsonWriter jsonWriter = newJsonWriter(Streams.writerForAppendable(writer));
  20. toJson(src, typeOfSrc, jsonWriter);
  21. } catch (IOException e) {
  22. throw new JsonIOException(e);
  23. }
  24. }

代码示例来源:origin: zycgit/hasor

  1. @Override
  2. public void writerJson(Object renderData, Writer writerTo) throws Throwable {
  3. JsonWriter jsonWriter = this.gson.newJsonWriter(writerTo);
  4. this.gson.toJson(renderData, renderData.getClass(), jsonWriter);
  5. }
  6. }

代码示例来源:origin: gradle.plugin.com.github.mazzeb/auto-version

  1. public void saveToFile(Version version) {
  2. try (JsonWriter writer = GSON.newJsonWriter(new FileWriter(fileName))) {
  3. GSON.toJson(version, Version.class, writer);
  4. } catch (IOException e) {
  5. e.printStackTrace();
  6. }
  7. }
  8. }

代码示例来源:origin: flipkart-incubator/proteus

  1. @Override
  2. public RequestBody convert(T value) throws IOException {
  3. //noinspection unchecked
  4. TypeAdapter<T> adapter = (TypeAdapter<T>) gson.getAdapter(TypeToken.get(type));
  5. Writer writer = new StringWriter();
  6. JsonWriter jsonWriter = gson.newJsonWriter(writer);
  7. adapter.write(jsonWriter, value);
  8. jsonWriter.close();
  9. return RequestBody.create(MEDIA_TYPE, URLEncoder.encode(writer.toString(), "UTF-8").getBytes());
  10. }
  11. }

代码示例来源:origin: Lauzy/TicktockMusic

  1. @Override
  2. public RequestBody convert(@NonNull T value) throws IOException {
  3. Buffer buffer = new Buffer();
  4. Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
  5. JsonWriter jsonWriter = gson.newJsonWriter(writer);
  6. adapter.write(jsonWriter, value);
  7. jsonWriter.close();
  8. return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
  9. }
  10. }

代码示例来源:origin: ShonLin/QuickDevFramework

  1. @Override
  2. public RequestBody convert(@NonNull T value) throws IOException {
  3. Buffer buffer = new Buffer();
  4. Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
  5. JsonWriter jsonWriter = gson.newJsonWriter(writer);
  6. adapter.write(jsonWriter, value);
  7. jsonWriter.close();
  8. return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
  9. }
  10. }

代码示例来源:origin: FussenYu/MVP_Project

  1. @Override
  2. public RequestBody convert(T value) throws IOException {
  3. Buffer buffer = new Buffer();
  4. Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
  5. JsonWriter jsonWriter = gson.newJsonWriter(writer);
  6. adapter.write(jsonWriter, value);
  7. jsonWriter.close();
  8. return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
  9. }
  10. }

代码示例来源:origin: lionoggo/Akit-Reader

  1. @Override
  2. public RequestBody convert(T value) throws IOException {
  3. Buffer buffer = new Buffer();
  4. Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
  5. JsonWriter jsonWriter = gson.newJsonWriter(writer);
  6. adapter.write(jsonWriter, value);
  7. jsonWriter.close();
  8. return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
  9. }
  10. }

代码示例来源:origin: lionoggo/FastApp

  1. @Override
  2. public RequestBody convert(T value) throws IOException {
  3. Buffer buffer = new Buffer();
  4. Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
  5. JsonWriter jsonWriter = gson.newJsonWriter(writer);
  6. adapter.write(jsonWriter, value);
  7. jsonWriter.close();
  8. return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
  9. }
  10. }

代码示例来源:origin: lionoggo/FastApp

  1. @Override
  2. public RequestBody convert(T value) throws IOException {
  3. Buffer buffer = new Buffer();
  4. Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
  5. JsonWriter jsonWriter = gson.newJsonWriter(writer);
  6. adapter.write(jsonWriter, value);
  7. jsonWriter.close();
  8. return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
  9. }
  10. }

代码示例来源:origin: zhpanvip/Retrofit2

  1. @Override
  2. public RequestBody convert(T value) throws IOException {
  3. Buffer buffer = new Buffer();
  4. Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
  5. JsonWriter jsonWriter = gson.newJsonWriter(writer);
  6. adapter.write(jsonWriter, value);
  7. jsonWriter.close();
  8. return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
  9. }
  10. }

代码示例来源:origin: 736008081/frameAndroid

  1. @Override
  2. public RequestBody convert(T value) throws IOException {
  3. Buffer buffer = new Buffer();
  4. Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
  5. JsonWriter jsonWriter = gson.newJsonWriter(writer);
  6. adapter.write(jsonWriter, value);
  7. jsonWriter.close();
  8. return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
  9. }
  10. }

代码示例来源:origin: 348476129/gank.io-with-MVVM

  1. @Override
  2. public RequestBody convert(T value) throws IOException {
  3. Buffer buffer = new Buffer();
  4. Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
  5. JsonWriter jsonWriter = gson.newJsonWriter(writer);
  6. adapter.write(jsonWriter, value);
  7. jsonWriter.close();
  8. return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
  9. }
  10. }

代码示例来源:origin: lionoggo/Akit-Reader

  1. @Override
  2. public RequestBody convert(T value) throws IOException {
  3. Buffer buffer = new Buffer();
  4. Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
  5. JsonWriter jsonWriter = gson.newJsonWriter(writer);
  6. adapter.write(jsonWriter, value);
  7. jsonWriter.close();
  8. return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
  9. }
  10. }

代码示例来源:origin: vaibhav-sinha/kong-java-client

  1. @Override
  2. public RequestBody convert(T value) throws IOException {
  3. Buffer buffer = new Buffer();
  4. Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
  5. JsonWriter jsonWriter = gson.newJsonWriter(writer);
  6. adapter.write(jsonWriter, value);
  7. jsonWriter.close();
  8. return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
  9. }
  10. }

代码示例来源:origin: flipkart-incubator/proteus

  1. @Override
  2. public RequestBody convert(T value) throws IOException {
  3. TypeAdapter<T> adapter = getAdapter();
  4. Buffer buffer = new Buffer();
  5. Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
  6. JsonWriter jsonWriter = gson.newJsonWriter(writer);
  7. jsonWriter.setSerializeNulls(true);
  8. adapter.write(jsonWriter, value);
  9. jsonWriter.close();
  10. return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
  11. }
  12. }

相关文章