Interface JsonTypeAdapter<T>


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.

  • Method Summary

    Modifier and Type
    Method
    Description
    The value json is the form of; json may be null.
    toJson(T value)
    The JSON form of value, which may be null.
  • Method Details

    • toJson

      Object toJson(T value)

      The JSON form of value, which may be null.

      Parameters
      • value: the value to write
      Returns

      its parsed JSON form

    • fromJson

      T fromJson(Object json)

      The value json is the form of; json may be null.

      Parameters
      • json: the parsed JSON value
      Returns

      the value it stands for