Retrofit2.0遇到的问题1+beta2更新无标题文章

Retrofit请求的body中传递json在bean转换时和activeandroid的Model冲突

  • 代码:
@Table(name = "ShoppingCart")
public class Good extends Model{
    public Good() {
    }

    /**
     * 商品名称
     */
    @Column(name = "Name")
    public String name;
    ...
}
HttpUtil.getRetrofit()
                .create(IHomeData.class)
                .homeDate(new Good(""))
                .enqueue(new Callback>() {
                ...}

Retrofit beta2增加了对表单请求的支持(其实beta1就支持)

@FormUrlEncoded
@POST("/user/edit")
Call updateUser(@Field("first_name") String first, @Field("last_name") String last);
  • 在beta1时官方并没有说明表单请求如何发送,使我研究了很久才得到解决
    (见Retrofit2.0初步使用指南+设置Retrofit的公用头部和日志输出
  • 完整更新日志:
Change Log
Version 2.0.0-beta2 (2015-09-28)

    New: Using a response type of Void (e.g., Call) will ignore and discard the response body. This can be used when there will be no response body (such as in a 201 response) or whenever the body is not needed. @Head requests are now forced to use this as their response type.
    New: validateEagerly() method on Retrofit.Builder will verify the correctness of all service methods on calls to create() instead of lazily validating on first use.
    New: Converter is now parameterized over both 'from' and 'to' types with a single convert method. Converter.Factory is now an abstract class and has factory methods for both request body and response body.
    New: Converter.Factory and CallAdapter.Factory now receive the method annotations when being created for a return/response type and the parameter annotations when being created for a parameter type.
    New: callAdapter() method on Retrofit allows querying a CallAdapter for a given type. The nextCallAdapter() method allows delegating to another CallAdapter from within a CallAdapter.Factory. This is useful for composing call adapters to incrementally build up behavior.
    New: requestConverter() and responseConverter() methods on Retrofit allow querying a Converter for a given type.
    New: onResponse method in Callback now receives the Retrofit instance. Combined with the responseConverter() method on Retrofit, this provides a way of deserializing an error body on Response. See the DeserializeErrorBody sample for an example.
    New: The MoshiConverterFactory has been updated for its v1.0.0.
    Fix: Using ResponseBody for the response type or RequestBody for a parameter type is now correctly identified. Previously these types would erroneously be passed to the supplied converter.
    Fix: The encoding of @Path values has been corrected to conform to OkHttp's HttpUrl.
    Fix: Use form-data content disposition subtype for @Multipart.
    Fix: Observable and Single-based execution of requests now behave synchronously (and thus requires subscribeOn() for running in the background).
    Fix: Correct GsonConverterFactory to honor the configuration of the Gson instances (such as not serializing null values, the default).

此为blog备份,原地址:http://blog.yzapp.cn/Retrofit2.html

你可能感兴趣的:(Retrofit2.0遇到的问题1+beta2更新无标题文章)