Moshi v1.4.0 Release Notes

Release Date: 2017-02-04 // about 7 years ago
  • 2017-02-04

    Moshi 1.4 is a major release that adds JSON values as a core part of the library. We consider any Java object comprised of maps, lists, strings, numbers, booleans and nulls to be a JSON value. These 📜 are equivalent to parsed JSON objects in JavaScript, [Gson][gson]’s JsonElement, and [Jackson][jackson]’s JsonNode. Unlike Jackson and Gson, Moshi just uses Java’s built-in types for its values:

    JSON typeJava type {...}ObjectMap<String, Object> [...]ArrayList<Object> "abc"StringString 123NumberDouble, Long, or BigDecimal trueBooleanBoolean nullnullnull

    Moshi's new API JsonAdapter.toJsonValue() converts your application classes to JSON values comprised of the above types. Symmetrically, JsonAdapter.fromJsonValue() converts JSON values to your application classes.

    • New: JsonAdapter.toJsonValue() and fromJsonValue().
    • New: JsonReader.readJsonValue() reads a JSON value from a stream.
    • New: Moshi.adapter(Type, Class<? extends Annotation>) lets you look up the adapter for a qualified type.
    • New: JsonAdapter.serializeNulls() and indent() return JSON adapters that customize the format of the encoded JSON.
    • New: JsonReader.selectName() and selectString() optimize decoding JSON with known names and values.
    • New: Types.nextAnnotations() reduces the amount of code required to implement a custom JsonAdapter.Factory.
    • Fix: Don't fail on large longs that have a fractional component like 9223372036854775806.0.