List of usage examples for com.google.gson.stream JsonWriter getSerializeNulls
public final boolean getSerializeNulls()
From source file:com.vaadin.addon.charts.model.gsonhelpers.TitleTypeAdapterFactory.java
private TypeAdapter<Title> customizeMyClassAdapter(Gson gson, TypeToken<Title> type) { final TypeAdapter<Title> delegate = gson.getDelegateAdapter(this, type); final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class); return new TypeAdapter<Title>() { @Override/*from w w w . j av a 2s . c om*/ public void write(JsonWriter out, Title value) throws IOException { // null for text is significant, else there will be // "Chart Title" as default if (value != null && value.getText() == null) { boolean serializeNulls = out.getSerializeNulls(); out.setSerializeNulls(true); out.beginObject(); out.name("text"); out.nullValue(); out.endObject(); out.setSerializeNulls(serializeNulls); } else { elementAdapter.write(out, delegate.toJsonTree(value)); } } // This is never used @Override public Title read(JsonReader in) throws IOException { JsonElement tree = elementAdapter.read(in); return delegate.fromJsonTree(tree); } }; }
From source file:org.eclipse.lsp4j.adapters.InitializeParamsTypeAdapter.java
License:Open Source License
protected void writeProcessId(final JsonWriter out, final Integer value) throws IOException { if ((value == null)) { final boolean previousSerializeNulls = out.getSerializeNulls(); out.setSerializeNulls(true);// www. j a v a 2 s. c om out.nullValue(); out.setSerializeNulls(previousSerializeNulls); } else { out.value(value); } }
From source file:org.eclipse.lsp4j.adapters.InitializeParamsTypeAdapter.java
License:Open Source License
protected void writeRootUri(final JsonWriter out, final String value) throws IOException { if ((value == null)) { final boolean previousSerializeNulls = out.getSerializeNulls(); out.setSerializeNulls(true);// ww w . j av a 2 s . c o m out.nullValue(); out.setSerializeNulls(previousSerializeNulls); } else { out.value(value); } }
From source file:org.eclipse.lsp4j.adapters.VersionedTextDocumentIdentifierTypeAdapter.java
License:Open Source License
protected void writeVersion(final JsonWriter out, final Integer value) throws IOException { if ((value == null)) { final boolean previousSerializeNulls = out.getSerializeNulls(); out.setSerializeNulls(true);// www. j a v a 2 s . co m out.nullValue(); out.setSerializeNulls(previousSerializeNulls); } else { out.value(value); } }
From source file:org.eclipse.lsp4j.jsonrpc.json.adapters.MessageTypeAdapter.java
License:Open Source License
/** * Use this method to write a {@code null} value even if the JSON writer is set to not serialize {@code null}. *///from w w w . jav a 2 s . c om protected void writeNullValue(JsonWriter out) throws IOException { boolean previousSerializeNulls = out.getSerializeNulls(); out.setSerializeNulls(true); out.nullValue(); out.setSerializeNulls(previousSerializeNulls); }
From source file:org.hibernate.search.elasticsearch.util.impl.gson.ES2FieldDataTypeJsonAdapter.java
License:LGPL
@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);/*from w w w . ja va 2 s.com*/ out.nullValue(); out.setSerializeNulls(previousSerializeNulls); }
From source file:org.hibernate.search.elasticsearch.util.impl.gson.ES2NormsTypeJsonAdapter.java
License:LGPL
@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);//from ww w . j a v a2 s . c o m out.nullValue(); out.setSerializeNulls(previousSerializeNulls); }
From source file:org.jclouds.json.internal.NullHackJsonLiteralAdapter.java
License:Apache License
@Override public void write(JsonWriter jsonWriter, L value) throws IOException { Writer writer = getWriter(jsonWriter); boolean serializeNulls = jsonWriter.getSerializeNulls(); try {/*from ww w .j a v a 2 s .c om*/ // we are using an implementation hack which depends on replacing null with the raw json // supplied as a parameter. In this case, we must ensure we indeed serialize nulls. NullReplacingWriter nullReplacingWriter = new NullReplacingWriter(writer, toString(value)); setWriter(jsonWriter, nullReplacingWriter); jsonWriter.setSerializeNulls(true); jsonWriter.nullValue(); } finally { setWriter(jsonWriter, writer); jsonWriter.setSerializeNulls(serializeNulls); } }