2014-08-09 16:13:20 +00:00
|
|
|
|
Change Log
|
|
|
|
|
==========
|
|
|
|
|
|
2018-11-08 23:01:07 +00:00
|
|
|
|
## Version 1.8.0
|
|
|
|
|
|
|
|
|
|
_2018-11-09_
|
|
|
|
|
|
|
|
|
|
* New: Support JSON objects that include type information in the JSON. The new
|
|
|
|
|
`PolymorphicJsonAdapterFactory` writes a type field when encoding, and reads it when decoding.
|
|
|
|
|
* New: Fall back to the reflection-based `KotlinJsonAdapterFactory` if it is enabled and a
|
|
|
|
|
generated adapter is not found. This makes it possible to use reflection-based JSON adapters in
|
|
|
|
|
development (so you don't have to wait for code to be regenerated on every build) and generated
|
|
|
|
|
JSON adapters in production (so you don't need the kotlin-reflect library).
|
|
|
|
|
* New: The `peekJson()` method on `JsonReader` let you read ahead on a JSON stream without
|
|
|
|
|
consuming it. This builds on Okio's new `Buffer.peek()` API.
|
|
|
|
|
* New: The `beginFlatten()` and `endFlatten()` methods on `JsonWriter` suppress unwanted nesting
|
|
|
|
|
when composing adapters. Previously it was necessary to flatten objects in memory before writing.
|
2018-11-10 19:42:18 +00:00
|
|
|
|
* New: Upgrade to Okio 1.16.0. We don't yet require Kotlin-friendly Okio 2.1 but Moshi works fine
|
2018-11-08 23:01:07 +00:00
|
|
|
|
with that release.
|
|
|
|
|
|
|
|
|
|
```kotlin
|
|
|
|
|
implementation("com.squareup.okio:okio:1.16.0")
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
* Fix: Don't return partially-constructed adapters when using a Moshi instance concurrently.
|
|
|
|
|
* Fix: Eliminate warnings and errors in generated `.kt` triggered by type variance, primitive
|
|
|
|
|
types, and required values.
|
|
|
|
|
* Fix: Improve the supplied rules (`moshi.pro`) to better retain symbols used by Moshi. We
|
|
|
|
|
recommend R8 when shrinking code.
|
|
|
|
|
* Fix: Remove code generation companion objects. This API was neither complete nor necessary.
|
|
|
|
|
|
|
|
|
|
|
2018-09-25 02:26:55 +00:00
|
|
|
|
## Version 1.7.0
|
|
|
|
|
|
|
|
|
|
_2018-09-24_
|
|
|
|
|
|
|
|
|
|
* New: `EnumJsonAdapter` makes it easy to specify a fallback value for unknown enum constants.
|
|
|
|
|
By default Moshi throws an `JsonDataException` if it reads an unknown enum constant. With this
|
|
|
|
|
you can specify a fallback value or null.
|
|
|
|
|
|
|
|
|
|
```java
|
|
|
|
|
new Moshi.Builder()
|
|
|
|
|
.add(EnumJsonAdapter.create(IsoCurrency.class)
|
|
|
|
|
.withUnknownFallback(IsoCurrency.USD))
|
|
|
|
|
.build();
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Note that this adapter is in the optional `moshi-adapters` module.
|
|
|
|
|
|
|
|
|
|
```groovy
|
|
|
|
|
implementation 'com.squareup.moshi:moshi-adapters:1.7.0'
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
* New: Embed R8/ProGuard rules in the `.jar` file.
|
|
|
|
|
* New: Use `@CheckReturnValue` in more places. We hope this will encourage you to use `skipName()`
|
|
|
|
|
instead of `nextName()` for better performance!
|
|
|
|
|
* New: Forbid automatic encoding of platform classes in `androidx`. As with `java.*`, `android.*`,
|
|
|
|
|
and `kotlin.*` Moshi wants you to specify how to encode platform types.
|
|
|
|
|
* New: Improve error reporting when creating an adapter fails.
|
|
|
|
|
* New: Upgrade to Okio 1.15.0. We don't yet require Kotlin-friendly Okio 2.x but Moshi works fine
|
|
|
|
|
with that release.
|
|
|
|
|
|
|
|
|
|
```groovy
|
|
|
|
|
implementation 'com.squareup.okio:okio:1.15.0'
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
* Fix: Return false from `JsonReader.hasNext()` at document's end.
|
|
|
|
|
* Fix: Improve code gen to handle several broken cases. Our generated adapters had problems with
|
|
|
|
|
nulls, nested parameterized types, private transient properties, generic type aliases, fields
|
|
|
|
|
with dollar signs in their names, and named companion objects.
|
|
|
|
|
|
|
|
|
|
|
2018-05-15 01:53:27 +00:00
|
|
|
|
## Version 1.6.0
|
2018-05-07 01:48:28 +00:00
|
|
|
|
|
2018-05-15 01:53:27 +00:00
|
|
|
|
_2018-05-14_
|
|
|
|
|
|
|
|
|
|
* **Moshi now supports codegen for Kotlin.** We've added a new annotation processor that generates
|
|
|
|
|
a small and fast JSON adapter for your Kotlin types. It can be used on its own or with the
|
|
|
|
|
existing `KotlinJsonAdapterFactory` adapter.
|
2018-05-07 01:48:28 +00:00
|
|
|
|
|
|
|
|
|
* **Moshi now resolves all type parameters.** Previously Moshi wouldn't resolve type parameters on
|
|
|
|
|
top-level classes.
|
2018-05-15 01:53:27 +00:00
|
|
|
|
|
2018-05-07 01:48:28 +00:00
|
|
|
|
* New: Support up to 255 levels of nesting when reading and writing JSON. Previously Moshi would
|
|
|
|
|
reject JSON input that contained more than 32 levels of nesting.
|
|
|
|
|
* New: Write encoded JSON to a stream with `JsonWriter.value(BufferedSource)`. Use this to emit a
|
|
|
|
|
JSON value without decoding it first.
|
|
|
|
|
* New: `JsonAdapter.nonNull()` returns a new JSON adapter that forbids explicit nulls in the JSON
|
|
|
|
|
body. Use this to detect and fail eagerly on unwanted nulls.
|
|
|
|
|
* New: `JsonReader.skipName()` is like `nextName()` but it avoids allocating when a name is
|
|
|
|
|
unknown. Use this when `JsonReader.selectName()` returns -1.
|
|
|
|
|
* New: Automatic module name of `com.squareup.moshi` for use with the Java Platform Module System.
|
2018-05-15 01:53:27 +00:00
|
|
|
|
This moves moshi-adapters into its own `.adapters` package and forwards the existing adapter. It
|
|
|
|
|
moves the moshi-kotlin into its own `.kotlin.reflect` package and forwards the existing adapter.
|
|
|
|
|
* New: Upgrade to Okio 1.14.0.
|
2018-05-07 01:48:28 +00:00
|
|
|
|
|
|
|
|
|
```xml
|
|
|
|
|
<dependency>
|
|
|
|
|
<groupId>com.squareup.okio</groupId>
|
|
|
|
|
<artifactId>okio</artifactId>
|
2018-05-15 01:53:27 +00:00
|
|
|
|
<version>1.14.0</version>
|
2018-05-07 01:48:28 +00:00
|
|
|
|
</dependency>
|
|
|
|
|
|
2018-05-15 01:53:27 +00:00
|
|
|
|
com.squareup.okio:okio:1.14.0
|
2018-05-07 01:48:28 +00:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
* Fix: Fail fast if there are trailing non-whitespace characters in the JSON passed to
|
|
|
|
|
`JsonAdapter.fromJson(String)`. Previously such data was ignored!
|
|
|
|
|
* Fix: Fail fast when Kotlin types are abstract, inner, or object instances.
|
|
|
|
|
* Fix: Fail fast if `name()` is called out of sequence.
|
|
|
|
|
* Fix: Handle asymmetric `Type.equals()` methods when doing type comparisons. Previously it was
|
|
|
|
|
possible that a registered type adapter would not be used because its `Type.equals()` method was
|
|
|
|
|
not consistent with a user-provided type.
|
|
|
|
|
* Fix: `JsonValueReader.selectString()` now returns -1 for non-strings instead of throwing.
|
|
|
|
|
* Fix: Permit reading numbers as strings when the `JsonReader` was created from a JSON value. This
|
|
|
|
|
was always supported when reading from a stream but broken when reading from a decoded value.
|
|
|
|
|
* Fix: Delegate to user-adapters in the adapter for Object.class. Previously when Moshi encountered
|
|
|
|
|
an opaque Object it would only use the built-in adapters. With this change user-installed
|
|
|
|
|
adapters for types like `String` will always be honored.
|
|
|
|
|
|
2017-05-15 02:02:51 +00:00
|
|
|
|
## Version 1.5.0
|
|
|
|
|
|
|
|
|
|
_2017-05-14_
|
|
|
|
|
|
|
|
|
|
* **Moshi now uses `@Nullable` to annotate all possibly-null values.** We've added a compile-time
|
|
|
|
|
dependency on the JSR 305 annotations. This is a [provided][maven_provided] dependency and does
|
|
|
|
|
not need to be included in your build configuration, `.jar` file, or `.apk`. We use
|
|
|
|
|
`@ParametersAreNonnullByDefault` and all parameters and return types are never null unless
|
|
|
|
|
explicitly annotated `@Nullable`.
|
|
|
|
|
|
|
|
|
|
* **Warning: Moshi APIs in this update are source-incompatible for Kotlin callers.** Nullability
|
|
|
|
|
was previously ambiguous and lenient but now the compiler will enforce strict null checks.
|
|
|
|
|
|
|
|
|
|
* **Kotlin models are now supported via the `moshi-kotlin` extension.** `KotlinJsonAdapterFactory`
|
|
|
|
|
is the best way to use Kotlin with Moshi. It honors default values and is null-safe. Kotlin
|
|
|
|
|
users that don't use this factory should write custom adapters for their JSON types. Otherwise
|
|
|
|
|
Moshi cannot properly initialize delegated properties of the objects it decodes.
|
|
|
|
|
|
|
|
|
|
* New: Upgrade to Okio 1.13.0.
|
|
|
|
|
|
|
|
|
|
```xml
|
|
|
|
|
<dependency>
|
|
|
|
|
<groupId>com.squareup.okio</groupId>
|
|
|
|
|
<artifactId>okio</artifactId>
|
|
|
|
|
<version>1.13.0</version>
|
|
|
|
|
</dependency>
|
|
|
|
|
|
|
|
|
|
com.squareup.okio:okio:1.13.0
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
* New: You may now declare delegates in `@ToJson` and `@FromJson` methods. If one of the arguments
|
|
|
|
|
to the method is a `JsonAdapter` of the same type, that will be the next eligible adapter for
|
|
|
|
|
that type. This may be useful for composing adapters.
|
|
|
|
|
* New: `Types.equals(Type, Type)` makes it easier to compare types in `JsonAdapter.Factory`.
|
|
|
|
|
* Fix: Retain the sign on negative zero.
|
|
|
|
|
|
|
|
|
|
|
2017-02-04 20:17:34 +00:00
|
|
|
|
## Version 1.4.0
|
|
|
|
|
|
|
|
|
|
_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:
|
|
|
|
|
|
|
|
|
|
<table>
|
|
|
|
|
<tr><th></th><th>JSON type</th><th>Java type</th></tr>
|
|
|
|
|
<tr><td>{...}</td><td>Object</td><td>Map<String, Object></th></tr>
|
|
|
|
|
<tr><td>[...]</td><td>Array</td><td>List<Object></th></tr>
|
|
|
|
|
<tr><td>"abc"</td><td>String</td><td>String</th></tr>
|
|
|
|
|
<tr><td>123</td><td>Number</td><td>Double, Long, or BigDecimal</th></tr>
|
|
|
|
|
<tr><td>true</td><td>Boolean</td><td>Boolean</th></tr>
|
|
|
|
|
<tr><td>null</td><td>null</td><td>null</th></tr>
|
|
|
|
|
</table>
|
|
|
|
|
|
|
|
|
|
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.
|
2017-02-04 23:39:35 +00:00
|
|
|
|
* New: `Types.nextAnnotations()` reduces the amount of code required to implement a custom
|
|
|
|
|
`JsonAdapter.Factory`.
|
2017-02-04 20:17:34 +00:00
|
|
|
|
* Fix: Don't fail on large longs that have a fractional component like `9223372036854775806.0`.
|
|
|
|
|
|
2016-10-21 13:34:32 +00:00
|
|
|
|
## Version 1.3.1
|
|
|
|
|
|
|
|
|
|
_2016-10-21_
|
|
|
|
|
|
|
|
|
|
* Fix: Don't incorrectly report invalid input when a slash character is escaped. When we tightened
|
|
|
|
|
our invalid escape handling we missed the one character that is valid both escaped `\/` and
|
|
|
|
|
unescaped `/`.
|
|
|
|
|
|
2016-10-15 18:16:55 +00:00
|
|
|
|
## Version 1.3.0
|
|
|
|
|
|
|
|
|
|
_2016-10-15_
|
|
|
|
|
|
2016-10-17 13:26:57 +00:00
|
|
|
|
* New: Permit `@ToJson` and `@FromJson` methods to take any number of `JsonAdapter` parameters to
|
2016-10-15 18:16:55 +00:00
|
|
|
|
delegate to. This is supported for `@ToJson` methods that take a `JsonWriter` and `@FromJson`
|
|
|
|
|
methods that take a `JsonReader`.
|
|
|
|
|
* New: Throw `JsonEncodingException` when the incoming data is not valid JSON. Use this to
|
|
|
|
|
differentiate data format problems from connectivity problems.
|
|
|
|
|
* New: Upgrade to Okio 1.11.0.
|
|
|
|
|
|
|
|
|
|
```xml
|
|
|
|
|
<dependency>
|
|
|
|
|
<groupId>com.squareup.okio</groupId>
|
|
|
|
|
<artifactId>okio</artifactId>
|
|
|
|
|
<version>1.11.0</version>
|
|
|
|
|
</dependency>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
* New: Omit Kotlin (`kotlin.*`) and Scala (`scala.*`) platform types when encoding objects using
|
|
|
|
|
their fields. This should make it easier to avoid unexpected dependencies on platform versions.
|
|
|
|
|
* Fix: Explicitly limit reading and writing to 31 levels of nested structure. Previously no
|
|
|
|
|
specific limit was enforced, but deeply nested documents would fail with either an
|
|
|
|
|
`ArrayIndexOutOfBoundsException` due to a bug in `JsonWriter`'s path management, or a
|
|
|
|
|
`StackOverflowError` due to excessive recursion.
|
|
|
|
|
* Fix: Require enclosed types to specify their enclosing type with
|
|
|
|
|
`Types.newParameterizedTypeWithOwner()`. Previously this API did not exist and looking up
|
2017-11-05 21:57:59 +00:00
|
|
|
|
adapters for enclosed parameterized types was not possible.
|
2016-10-15 18:16:55 +00:00
|
|
|
|
* Fix: Fail on invalid escapes. Previously any character could be escaped. With this fix only
|
|
|
|
|
characters permitted to be escaped may be escaped. Use `JsonReader.setLenient(true)` to read
|
|
|
|
|
JSON documents that escape characters that should not be escaped.
|
|
|
|
|
|
2016-05-28 18:25:36 +00:00
|
|
|
|
## Version 1.2.0
|
|
|
|
|
|
|
|
|
|
_2016-05-28_
|
|
|
|
|
|
|
|
|
|
* New: Take advantage of Okio's new `Options` feature when reading field names and enum values.
|
|
|
|
|
This has a significant impact on performance. We measured parsing performance improve from 89k
|
|
|
|
|
ops/sec to 140k ops/sec on one benchmark on one machine.
|
|
|
|
|
* New: Upgrade to Okio 1.8.0.
|
|
|
|
|
|
|
|
|
|
```xml
|
|
|
|
|
<dependency>
|
|
|
|
|
<groupId>com.squareup.okio</groupId>
|
|
|
|
|
<artifactId>okio</artifactId>
|
|
|
|
|
<version>1.8.0</version>
|
|
|
|
|
</dependency>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
* New: Support types that lack no-argument constructors objects on Android releases prior to
|
|
|
|
|
Gingerbread.
|
|
|
|
|
* Fix: Add writer value overload for boxed booleans. Autoboxing resolves boxed longs and doubles
|
|
|
|
|
to `value(Number)`, but a boxed boolean would otherwise resolve to value(boolean) with an
|
|
|
|
|
implicit call to booleanValue() which has the potential to throw NPEs.
|
|
|
|
|
* Fix: Be more aggressive about canonicalizing types.
|
|
|
|
|
|
2016-01-18 22:16:20 +00:00
|
|
|
|
## Version 1.1.0
|
|
|
|
|
|
|
|
|
|
_2016-01-19_
|
|
|
|
|
|
2016-05-28 18:25:36 +00:00
|
|
|
|
* New: Support [RFC 7159][rfc_7159], the latest JSON specification. This removes the constraint
|
|
|
|
|
that the root value must be an array or an object. It may now take any value: array, object,
|
|
|
|
|
string, number, boolean, or null. Previously this was only permitted if the adapter was
|
|
|
|
|
configured to be lenient.
|
|
|
|
|
* New: Enum constants may be annotated with `@Json` to customize their encoded value.
|
|
|
|
|
* New: Create new builder from Moshi instance with `Moshi.newBuilder()`.
|
|
|
|
|
* New: `Types.getRawType()` and `Types.collectionElementType()` APIs to assist in defining generic
|
|
|
|
|
type adapter factories.
|
2016-01-18 22:16:20 +00:00
|
|
|
|
|
2015-09-27 17:23:59 +00:00
|
|
|
|
## Version 1.0.0
|
|
|
|
|
|
|
|
|
|
_2015-09-27_
|
|
|
|
|
|
2016-05-28 18:25:36 +00:00
|
|
|
|
* **API Change**: Replaced `new JsonReader()` with `JsonReader.of()` and `new JsonWriter()` with
|
|
|
|
|
`JsonWriter.of()`. If your code calls either of these constructors it will need to be updated to
|
|
|
|
|
call the static factory method instead.
|
|
|
|
|
* **API Change**: Don’t throw `IOException` on `JsonAdapter.toJson(T)`. Code that calls this
|
|
|
|
|
method may need to be fixed to no longer catch an impossible `IOException`.
|
|
|
|
|
* Fix: the JSON adapter for `Object` no longer fails when encountering `null` in the stream.
|
|
|
|
|
* New: `@Json` annotation can customize a field's name. This is particularly handy for fields
|
|
|
|
|
whose names are Java keywords, like `default` or `public`.
|
|
|
|
|
* New: `Rfc3339DateJsonAdapter` converts between a `java.util.Date` and a string formatted with
|
|
|
|
|
RFC 3339 (like `2015-09-26T18:23:50.250Z`). This class is in the new `moshi-adapters`
|
|
|
|
|
subproject. You will need to register this adapter if you want this date formatting behavior.
|
|
|
|
|
See it in action in the [dates example][dates_example].
|
|
|
|
|
* New: `Moshi.adapter()` keeps a cache of all created adapters. For best efficiency, application
|
|
|
|
|
code should keep a reference to required adapters in a field.
|
|
|
|
|
* New: The `Types` factory class makes it possible to compose types like `List<Card>` or
|
|
|
|
|
`Map<String, Integer>`. This is useful to look up JSON adapters for parameterized types.
|
2017-05-10 11:19:34 +00:00
|
|
|
|
* New: `JsonAdapter.failOnUnknown()` returns a new JSON adapter that throws if an unknown value is
|
2016-05-28 18:25:36 +00:00
|
|
|
|
encountered on the stream. Use this in development and debug builds to detect typos in field
|
|
|
|
|
names. This feature shouldn’t be used in production because it makes migrations very difficult.
|
2015-09-27 17:23:59 +00:00
|
|
|
|
|
2015-06-16 11:55:46 +00:00
|
|
|
|
## Version 0.9.0
|
2014-08-09 16:13:20 +00:00
|
|
|
|
|
2015-06-16 11:55:46 +00:00
|
|
|
|
_2015-06-16_
|
2014-08-09 16:13:20 +00:00
|
|
|
|
|
2016-05-28 18:25:36 +00:00
|
|
|
|
* Databinding for primitive types, strings, enums, arrays, collections, and maps.
|
|
|
|
|
* Databinding for plain old Java objects.
|
|
|
|
|
* [JSONPath](http://goessner.net/articles/JsonPath/) support for both `JsonReader` and
|
|
|
|
|
`JsonWriter`.
|
|
|
|
|
* Throw `JsonDataException` when there’s a data binding problem.
|
|
|
|
|
* Adapter methods: `@ToJson` and `@FromJson`.
|
|
|
|
|
* Qualifier annotations: `@JsonQualifier` to permit different type adapters for the same Java
|
|
|
|
|
type.
|
|
|
|
|
* Imported code from Gson: `JsonReader`, `JsonWriter`. Also some internal classes:
|
|
|
|
|
`LinkedHashTreeMap` for hash-collision avoidance and `Types` for typesafe databinding.
|
2015-09-27 17:23:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[dates_example]: https://github.com/square/moshi/blob/master/examples/src/main/java/com/squareup/moshi/recipes/ReadAndWriteRfc3339Dates.java
|
2016-01-18 22:16:20 +00:00
|
|
|
|
[rfc_7159]: https://tools.ietf.org/html/rfc7159
|
2017-02-04 20:17:34 +00:00
|
|
|
|
[gson]: https://github.com/google/gson
|
|
|
|
|
[jackson]: http://wiki.fasterxml.com/JacksonHome
|
2017-05-15 02:02:51 +00:00
|
|
|
|
[maven_provided]: https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
|