gpt4 book ai didi

java - 我是否使用改造正确提交了此 POST 正文?

转载 作者:太空宇宙 更新时间:2023-11-04 12:32:56 24 4
gpt4 key购买 nike

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

body:
{
"<requestId>": {
"actionFoo": "objId"
},
"<requestId>": {
"actionBar": "objId"
}
}

requestId 是在客户端生成的唯一字符串。我正在为这些值生成 UUID。

所以我尝试使用像这样定义的 Api 来使用 Retrofit:

首先我定义了一个“ActionCommand”对象:

public class ActionCommand {

private String actionFoo;
private String actionBar;

}

并将其输入到 Hashmap 映射中。我使用了这样定义的 api:

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

后端肯定正确获取了 objectId,但没有正确获取 map 中的任何操作。我不确定我还应该如何发送这些参数

谢谢

最佳答案

像这样改变你的pojo类:

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 将是这样的;

package com.example;

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

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

@SerializedName("actionBar")
@Expose
private String actionBar;

/**
*
* @return
* The actionBar
*/
public String getActionBar() {
return actionBar;
}

/**
*
* @param actionBar
* The actionBar
*/
public void setActionBar(String actionBar) {
this.actionBar = actionBar;
}

}

关于java - 我是否使用改造正确提交了此 POST 正文?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37647817/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com