Java Code Examples for com.squareup.moshi.JsonWriter#value()
The following examples show how to use
com.squareup.moshi.JsonWriter#value() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EnumJsonAdapter.java From moshi with Apache License 2.0 | 5 votes |
@Override public void toJson(JsonWriter writer, T value) throws IOException { if (value == null) { throw new NullPointerException( "value was null! Wrap in .nullSafe() to write nullable values."); } writer.value(nameStrings[value.ordinal()]); }
Example 2
Source File: Rfc3339DateJsonAdapter.java From moshi with Apache License 2.0 | 5 votes |
@Override public synchronized void toJson(JsonWriter writer, Date value) throws IOException { if (value == null) { writer.nullValue(); } else { String string = Iso8601Utils.format(value); writer.value(string); } }
Example 3
Source File: MoshiHelper.java From moshi-jsonapi with MIT License | 4 votes |
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: Double doubleValue = reader.nextDouble(); if (Math.floor(doubleValue) == doubleValue) { writer.value(doubleValue.longValue()); } else { writer.value(doubleValue); } 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); } }
Example 4
Source File: FallbackEnumJsonAdapter.java From moshi-lazy-adapters with Apache License 2.0 | 4 votes |
@Override public void toJson(JsonWriter writer, T value) throws IOException { writer.value(nameStrings[value.ordinal()]); }
Example 5
Source File: FallbackEnum.java From moshi with Apache License 2.0 | 4 votes |
@Override public void toJson(JsonWriter writer, T value) throws IOException { writer.value(nameStrings[value.ordinal()]); }
Example 6
Source File: ByteStrings.java From moshi with Apache License 2.0 | 4 votes |
@Override public void toJson(JsonWriter writer, ByteString value) throws IOException { String string = value.base64(); writer.value(string); }