public abstract class JsonAdapter<T> extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
JsonAdapter.Factory |
Constructor and Description |
---|
JsonAdapter() |
Modifier and Type | Method and Description |
---|---|
JsonAdapter<T> |
failOnUnknown()
Returns a JSON adapter equal to this, but that throws a
JsonDataException when
unknown names and values are encountered. |
T |
fromJson(okio.BufferedSource source) |
abstract T |
fromJson(JsonReader reader) |
T |
fromJson(String string) |
T |
fromJsonValue(Object value)
Decodes a Java value object from
value , which must be comprised of maps, lists,
strings, numbers, booleans and nulls. |
JsonAdapter<T> |
indent(String indent)
Return a JSON adapter equal to this, but using
indent to control how the result is
formatted. |
JsonAdapter<T> |
lenient()
Returns a JSON adapter equal to this, but is lenient when reading and writing.
|
JsonAdapter<T> |
nonNull()
Returns a JSON adapter equal to this JSON adapter, but that refuses null values.
|
JsonAdapter<T> |
nullSafe()
Returns a JSON adapter equal to this JSON adapter, but with support for reading and writing
nulls.
|
JsonAdapter<T> |
serializeNulls()
Returns a JSON adapter equal to this JSON adapter, but that serializes nulls when encoding
JSON.
|
void |
toJson(okio.BufferedSink sink,
T value) |
abstract void |
toJson(JsonWriter writer,
T value) |
String |
toJson(T value) |
Object |
toJsonValue(T value)
Encodes
value as a Java value object comprised of maps, lists, strings, numbers,
booleans, and nulls. |
@CheckReturnValue @Nullable public abstract T fromJson(JsonReader reader) throws IOException
IOException
@CheckReturnValue @Nullable public final T fromJson(okio.BufferedSource source) throws IOException
IOException
@CheckReturnValue @Nullable public final T fromJson(String string) throws IOException
IOException
public abstract void toJson(JsonWriter writer, @Nullable T value) throws IOException
IOException
public final void toJson(okio.BufferedSink sink, @Nullable T value) throws IOException
IOException
@CheckReturnValue public final String toJson(@Nullable T value)
@CheckReturnValue @Nullable public final Object toJsonValue(@Nullable T value)
value
as a Java value object comprised of maps, lists, strings, numbers,
booleans, and nulls.
Values encoded using value(double)
or value(long)
are modeled with the
corresponding boxed type. Values encoded using value(Number)
are modeled as a
Long
for boxed integer types (Byte
, Short
, Integer
, and Long
), as a Double
for boxed floating point types (Float
and Double
),
and as a BigDecimal
for all other types.
@CheckReturnValue @Nullable public final T fromJsonValue(@Nullable Object value)
value
, which must be comprised of maps, lists,
strings, numbers, booleans and nulls.@CheckReturnValue public final JsonAdapter<T> serializeNulls()
@CheckReturnValue public final JsonAdapter<T> nullSafe()
@CheckReturnValue public final JsonAdapter<T> nonNull()
JsonDataException
.
Note that this adapter will not usually be invoked for absent values and so those must be handled elsewhere. This should only be used to fail on explicit nulls.
@CheckReturnValue public final JsonAdapter<T> lenient()
@CheckReturnValue public final JsonAdapter<T> failOnUnknown()
JsonDataException
when
unknown names and values are encountered.
This constraint applies to both the top-level message handled by this type adapter as well as
to nested messages.@CheckReturnValue public JsonAdapter<T> indent(String indent)
indent
to control how the result is
formatted. The indent
string to be repeated for each level of indentation in the
encoded document. If indent.isEmpty()
the encoded document will be compact. Otherwise
the encoded document will be more human-readable.indent
- a string containing only whitespace.Copyright © 2019. All rights reserved.