Java 改装后对象列表和列表<;多部件车身零件>;
改装2.4.0Java 改装后对象列表和列表<;多部件车身零件>;,java,android,serialization,retrofit,okhttp,Java,Android,Serialization,Retrofit,Okhttp,改装2.4.0 retrofit = new Retrofit.Builder() .baseUrl(BASE_URL) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .build(); 我需要
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
我需要在同一请求中发布对象列表和图片列表,如下所示:
@Multipart
@POST("api/debug/{id}/")
Call<ItemResponse> uploadItems(
@Path("id") int id,
@Part("items[]") List<Item> items,
@Part List<MultipartBody.Part> pictures);
问题似乎在于使用@Part
有什么诀窍吗?嗯,你就不能换一个吗
@Part(“items[])
与@Part
?然后,您将在JSON响应中获得与图片列表结构相同的结构。如果我这样做,将抛出一个错误:@Part annotation必须提供名称或使用MultipartBody.Part参数类型。(参数#2)好的,我看到问题了。我认为此解决方案将帮助您:。TL;DR您必须使用@PartMap注释来获取与多部分对象一起存在的对象列表。
{
"items": [
"{"description":"desc1","id":1,"title":"title1"}",
"{"description":"desc2","id":2,"title":"title2"}",
"{"description":"desc3","id":3,"title":"title3"}"
],
"picture1": {
"name": "picture1",
"size": "315.777KB"
},
"picture2": {
"name": "picture2",
"size": "207.821KB"
}
}