Retrofitを使ってPUTリクエストのパラメータに配列を渡す方法です。POSTでも同じです。
間違い
@FormUrlEncoded
@PUT("/tags.json")
void putTags(@Field("tags") List<String> tags,
Callback<Tag> cb);
このように書くと、配列ではなく1つ目のStringが渡されます。
Processing by TagsController#update as JSON
Parameters: {"tags"=>"hoge1"}
正解
@FormUrlEncoded
@PUT("/tags.json")
void putTags(@Field("tags[]") List<String> tags,
Callback<Tag> cb);
@Field
アノテーションにつける名前を tags[]
に変えれば配列が渡されます。
Processing by TagsController#update as JSON
Parameters: {"tags"=>["hoge1", "hoge2", "hoge3"]}
おまけ
List<String>
ではなく String[]
でも動きます。
@FormUrlEncoded
@PUT("/tags.json")
void putTags(@Field("tags[]") String[] tags,
Callback<Tag> cb);