Retrofit v2.0.0 Release Notes
Release Date: 2016-03-11 // about 8 years ago-
๐ Retrofit 2 is a major release focused on extensibility. The API changes are numerous but solve shortcomings of the previous version and provide a path for future enhancement.
๐ Because the release includes breaking API changes, we're changing the project's package name from
retrofit
toretrofit2
. This should make it possible for large applications and libraries to migrate incrementally. The Maven group ID is nowcom.squareup.retrofit2
. For an explanation of ๐ this strategy, see Jake Wharton's post, Java Interoperability Policy for Major Version โก๏ธ Updates.Service methods return
Call<T>
. This allows them to be executed synchronously or asynchronously using the same method definition. ACall
instance represents a single request/response pair so it can only be used once, but you canclone()
it for re-use. Invokingcancel()
will cancel in-flight requests or prevent the request from even being performed if it has not already.Multiple converters for multiple serialization formats. API calls returning different formats (like JSON, protocol buffers, and plain text) no longer need to be separated into separate service interfaces. Combine them together and add multiple converters. Converters are chosen based on the response type you declare. Gson is no longer included by default, so you will always need to add a converter for any serialization support. OkHttp's
RequestBody
andResponseBody
types can always be used without adding one, however.Call adapters allow different execution mechanisms. While
Call
is the built-in mechanism, support for additional ones can be added similar to how different converters can be added. RxJava'sObservable
support has moved into a separate artifact as a result, and support for Java 8'sCompletableFuture
and Guava'sListenableFuture
are also provided as additional artifacts.Generic response type includes HTTP information and deserialized body. You no longer have to choose between the deserialized body and reading HTTP information. Every
Call
automatically receives both via theResponse<T>
type and the RxJava, Guava, and Java 8 call adapters also support it.@Url for hypermedia-like APIs. When your API returns links for pagination, additional resources, or updated content they can now be used with a service method whose first parameter is annotated with
@Url
.
๐ Changes from beta 4:
- New:
RxJavaCallAdapterFactory
now supports service methods which returnCompletable
which ignores and discards response bodies, if any. - New:
RxJavaCallAdapterFactory
supports supplying a defaultScheduler
which will be used forsubscribeOn
on returnedObservable
,Single
, andCompletable
instances. - New:
MoshiConverterFactory
supports creating an instance which uses lenient parsing. - New:
@Part
can omit the part name and use OkHttp'sMultipartBody.Part
type for supplying parts. This lets you customize the headers, name, and filename and provide the part body in a single argument. - The
BaseUrl
interface and support for changeable base URLs was removed. This functionality can be done using an OkHttp interceptor and a sample showcasing it was added. Response.isSuccess()
was renamed toResponse.isSuccessful()
for parity with the name of OkHttp's version of that method.- Fix: Throw a more appropriate exception with a message when a resolved url (base URL + relative URL) is malformed.
- Fix:
GsonConverterFactory
now honors settings on theGson
instance (like leniency). - Fix:
ScalarsConverterFactory
now supports primitive scalar types in addition to boxed for response body parsing. - Fix:
Retrofit.callbackExecutor()
may now return an executor even when one was not explicitly provided. This allows customCallAdapter.Factory
implementations to use it when triggering callbacks to ensure they happen on the appropriate thread for the platform (e.g., Android).