Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.

public interface JsonTypeAdapter<T>

Converts a value to and from its JSON form, for a field or class marked JsonAdapter.

Both directions use the parsed form of JSON: null, a String, a Boolean, a Number, a java.util.Map with String keys for an object and a java.util.List for an array, nested as deeply as needed. A parser may hand a number over as any Number subclass, so read one through Number#longValue() or Number#doubleValue() rather than casting it to a particular class.

Throw IllegalArgumentException from fromJson(Object) to refuse a value; the generated code adds where in the document it was. T is the type converted.

Methods

public abstract Object toJson(T value)The JSON form of value, which may be null.
public abstract T fromJson(Object json)The value json is the form of; json may be null.

Method details

toJson

public abstract Object toJson(T value)
The JSON form of value, which may be null.

Parameters

value T
the value to write

Returns

its parsed JSON form

fromJson

public abstract T fromJson(Object json)
The value json is the form of; json may be null.

Parameters

json Object
the parsed JSON value

Returns

the value it stands for