好吧所以我得到了这个前端反应应用程序,当你选择要使用的程序版本我需要将该版本及其所有数据传递给我的宁静服务
所以我喜欢这个
fetch('http://localhost:8080/sleepy-oyster/v2/myResource/', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body JSON.stringify({
firstParam:this.state.version
})
})
是“this.state.version”看起来像这样
{resourceURI: "http://nexus.ad.hrm.se/nexus/service/local/reposit…ent/se/hrmsoftware/hrm/hrm-release/16.1-SNAPSHOT/", relativePath: "/se/hrmsoftware/hrm/hrm-release/16.1-SNAPSHOT/", text: "16.1-SNAPSHOT", leaf: false, lastModified: "2018-04-09 07:04:40.0 UTC", …}
所以基本上我想要作为路径参数发送的常规对象和被调用的休息服务看起来像
@POST
@Path("{version}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION JSON)
public void createOyster(@Context NexusResource version) {
restUtil.getVersionFromNexus(version);
}
我发送的对象是NexusResource,但我得到的只是null。有谁知道我怎么做到这一点?
以下是NexusResource类的外观
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"resourceURI",
"relativePath",
"text",
"leaf",
"lastModified",
"sizeOnDisk"
})
public class NexusResource {
@JsonProperty("resourceURI")
private String resourceURI;
@JsonProperty("relativePath")
private String relativePath;
@JsonProperty("text")
private String text;
@JsonProperty("leaf")
private Boolean leaf;
@JsonProperty("lastModified")
private String lastModified;
@JsonProperty("sizeOnDisk")
private Integer sizeOnDisk;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<>();
答案 0 :(得分:0)
请参阅注释@RequestBody
将您的代码更改为以下内容:
@PostMapping(value = "/xxx",
consumes = MediaType.APPLICATION_JSON_UTF8_VALUE,
produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public void createOyster(@RequestBody NexusResource version) {...}