public JsonWriter setSerializeNulls(boolean b) { this.stream.setSerializeNulls(b); return this; }
private JsonWriter(Writer writer) { this.stream = new com.google.gson.stream.JsonWriter(writer); this.stream.setSerializeNulls(false); this.stream.setLenient(false); this.serializeEmptyStrings = true; }
void setWriterOptions(JsonWriter writer) { writer.setSerializeNulls(serializeNulls); writer.setLenient(lenient); writer.setHtmlSafe(htmlSafe); writer.setIndent(prettyPrinting ? " " : ""); } }
/** * Returns a new JSON writer configured for the settings on this Gson instance. */ public JsonWriter newJsonWriter(Writer writer) throws IOException { if (generateNonExecutableJson) { writer.write(JSON_NON_EXECUTABLE_PREFIX); } JsonWriter jsonWriter = new JsonWriter(writer); if (prettyPrinting) { jsonWriter.setIndent(" "); } jsonWriter.setSerializeNulls(serializeNulls); return jsonWriter; }
@Override public JsonLikeWriter init() throws IOException { eventWriter = new JsonWriter(getWriter()); eventWriter.setSerializeNulls(true); if (isPrettyPrint()) { eventWriter.setIndent(" "); } blockType = BlockType.NONE; blockStack.clear(); return this; }
/** * 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); } catch (AssertionError e) { throw new AssertionError("AssertionError (GSON " + GsonBuildConfig.VERSION + "): " + e.getMessage(), e); } finally { writer.setLenient(oldLenient); writer.setHtmlSafe(oldHtmlSafe); writer.setSerializeNulls(oldSerializeNulls); } }
/** * Writes the JSON representation of {@code src} of type {@code typeOfSrc} to * {@code writer}. * @throws JsonIOException if there was a problem writing to the writer */ @SuppressWarnings("unchecked") public void toJson(Object src, Type typeOfSrc, JsonWriter writer) throws JsonIOException { TypeAdapter<?> adapter = getAdapter(TypeToken.get(typeOfSrc)); boolean oldLenient = writer.isLenient(); writer.setLenient(true); boolean oldHtmlSafe = writer.isHtmlSafe(); writer.setHtmlSafe(htmlSafe); boolean oldSerializeNulls = writer.getSerializeNulls(); writer.setSerializeNulls(serializeNulls); try { ((TypeAdapter<Object>) adapter).write(writer, src); } catch (IOException e) { throw new JsonIOException(e); } catch (AssertionError e) { throw new AssertionError("AssertionError (GSON " + GsonBuildConfig.VERSION + "): " + e.getMessage(), e); } finally { writer.setLenient(oldLenient); writer.setHtmlSafe(oldHtmlSafe); writer.setSerializeNulls(oldSerializeNulls); } }
@Override public void write(JsonWriter out, FieldDataType value) throws IOException { // Ignore the value: fielddata is not supported on ES2 boolean previousSerializeNulls = out.getSerializeNulls(); out.setSerializeNulls( false ); out.nullValue(); out.setSerializeNulls( previousSerializeNulls ); }
/** * Use this method to write a {@code null} value even if the JSON writer is set to not serialize {@code null}. */ protected void writeNullValue(JsonWriter out) throws IOException { boolean previousSerializeNulls = out.getSerializeNulls(); out.setSerializeNulls(true); out.nullValue(); out.setSerializeNulls(previousSerializeNulls); }
@Override public void write(JsonWriter out, NormsType value) throws IOException { // Ignore the value: we don't support norms on ES2 boolean previousSerializeNulls = out.getSerializeNulls(); out.setSerializeNulls( false ); out.nullValue(); out.setSerializeNulls( previousSerializeNulls ); }
/** * Use this method to write a {@code null} value even if the JSON writer is set to not serialize {@code null}. */ protected void writeNullValue(JsonWriter out) throws IOException { boolean previousSerializeNulls = out.getSerializeNulls(); out.setSerializeNulls(true); out.nullValue(); out.setSerializeNulls(previousSerializeNulls); }
protected void writeProcessId(final JsonWriter out, final Integer value) throws IOException { if ((value == null)) { final boolean previousSerializeNulls = out.getSerializeNulls(); out.setSerializeNulls(true); out.nullValue(); out.setSerializeNulls(previousSerializeNulls); } else { out.value(value); } }
protected void writeRootUri(final JsonWriter out, final String value) throws IOException { if ((value == null)) { final boolean previousSerializeNulls = out.getSerializeNulls(); out.setSerializeNulls(true); out.nullValue(); out.setSerializeNulls(previousSerializeNulls); } else { out.value(value); } }
protected void writeVersion(final JsonWriter out, final Integer value) throws IOException { if ((value == null)) { final boolean previousSerializeNulls = out.getSerializeNulls(); out.setSerializeNulls(true); out.nullValue(); out.setSerializeNulls(previousSerializeNulls); } else { out.value(value); } }
protected void writeProcessId(final JsonWriter out, final Integer value) throws IOException { if ((value == null)) { final boolean previousSerializeNulls = out.getSerializeNulls(); out.setSerializeNulls(true); out.nullValue(); out.setSerializeNulls(previousSerializeNulls); } else { out.value(value); } }
protected void writeVersion(final JsonWriter out, final Integer value) throws IOException { if ((value == null)) { final boolean previousSerializeNulls = out.getSerializeNulls(); out.setSerializeNulls(true); out.nullValue(); out.setSerializeNulls(previousSerializeNulls); } else { out.value(value); } }
private JsonWriter(Writer writer) { this.stream = new com.google.gson.stream.JsonWriter(writer); this.stream.setSerializeNulls(false); this.stream.setLenient(false); }
@Override public RequestBody convert(T value) throws IOException { TypeAdapter<T> adapter = getAdapter(); Buffer buffer = new Buffer(); Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8); JsonWriter jsonWriter = gson.newJsonWriter(writer); jsonWriter.setSerializeNulls(true); adapter.write(jsonWriter, value); jsonWriter.close(); return RequestBody.create(MEDIA_TYPE, buffer.readByteString()); } }
@Override public JsonLikeWriter init() throws IOException { eventWriter = new JsonWriter(getWriter()); eventWriter.setSerializeNulls(true); if (isPrettyPrint()) { eventWriter.setIndent(" "); } blockType = BlockType.NONE; blockStack.clear(); return this; }
void setWriterOptions(JsonWriter writer) { writer.setSerializeNulls(serializeNulls); writer.setLenient(lenient); writer.setHtmlSafe(htmlSafe); writer.setIndent(prettyPrinting ? " " : ""); } }