Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我是否使用改装正确提交此帖子正文?_Java_Android_Retrofit - Fatal编程技术网

Java 我是否使用改装正确提交此帖子正文?

Java 我是否使用改装正确提交此帖子正文?,java,android,retrofit,Java,Android,Retrofit,我尝试使用一个API,其中一个端点在一个POST正文中接受多个请求,如下所示: body: { "<requestId>": { "actionFoo": "objId" }, "<requestId>": { "actionBar": "objId" } } 并将其输入Hashmap。我使用的api定义如下: @POST("/path/{someObjectId}/commands") Map<String,ActionRespo

我尝试使用一个API,其中一个端点在一个POST正文中接受多个请求,如下所示:

body:
{
  "<requestId>": {
    "actionFoo": "objId"
  },
  "<requestId>": {
    "actionBar": "objId"
  }
}
并将其输入Hashmap。我使用的api定义如下:

@POST("/path/{someObjectId}/commands")
Map<String,ActionResponse> sendActions(@Path("someObjectId")String objectId, @Body Map<String, ActionCommand> actionMap);
package com.example;

    import javax.annotation.Generated;
    import com.google.gson.annotations.Expose;
    import com.google.gson.annotations.SerializedName;

    @Generated("org.jsonschema2pojo")
    public class MyPojo {

    @SerializedName("<requestId>")
    @Expose
    private RequestId requestId;

    /**
    * 
    * @return
    * The requestId
    */
    public RequestId getRequestId() {
    return requestId;
    }

    /**
    * 
    * @param requestId
    * The <requestId>
    */
    public void setRequestId(RequestId requestId) {
    this.requestId = requestId;
    }

    }
@POST(“/path/{someObjectId}/commands”)
Map sendActions(@Path(“someObjectId”)字符串objectId,@Body Map actionMap);
后端确实正确地获取了objectId,但没有映射中的任何操作。我不确定我应该如何发送这些参数


谢谢,

像这样更改您的pojo课程:

@POST("/path/{someObjectId}/commands")
Map<String,ActionResponse> sendActions(@Path("someObjectId")String objectId, @Body Map<String, ActionCommand> actionMap);
package com.example;

    import javax.annotation.Generated;
    import com.google.gson.annotations.Expose;
    import com.google.gson.annotations.SerializedName;

    @Generated("org.jsonschema2pojo")
    public class MyPojo {

    @SerializedName("<requestId>")
    @Expose
    private RequestId requestId;

    /**
    * 
    * @return
    * The requestId
    */
    public RequestId getRequestId() {
    return requestId;
    }

    /**
    * 
    * @param requestId
    * The <requestId>
    */
    public void setRequestId(RequestId requestId) {
    this.requestId = requestId;
    }

    }

如下更改您的pojo类:

@POST("/path/{someObjectId}/commands")
Map<String,ActionResponse> sendActions(@Path("someObjectId")String objectId, @Body Map<String, ActionCommand> actionMap);
package com.example;

    import javax.annotation.Generated;
    import com.google.gson.annotations.Expose;
    import com.google.gson.annotations.SerializedName;

    @Generated("org.jsonschema2pojo")
    public class MyPojo {

    @SerializedName("<requestId>")
    @Expose
    private RequestId requestId;

    /**
    * 
    * @return
    * The requestId
    */
    public RequestId getRequestId() {
    return requestId;
    }

    /**
    * 
    * @param requestId
    * The <requestId>
    */
    public void setRequestId(RequestId requestId) {
    this.requestId = requestId;
    }

    }

我的改装设置是正确的。问题是我遗漏了“application/json”标题

我的改装设置是正确的。问题是我遗漏了“application/json”标题

尝试是否有助于将属性公开。或者是否有一个公共getter为他们?尝试是否有助于使属性公开。还是有一个公众的救世主?