我正在尝试在spring控制器中检索嵌套的json并获取"客户端发送的请求在语法上是不正确的。"
如果我不做嵌套的json格式,我的代码正在运行并获得正确的数据绑定,因此我可以得出结论,在我的DTO中可能有些不正确。
CURL命令:
CURL -i -H "Content-Type: application/json" -X POST http://localhost:8080/insertMapping -d '{"mapping": {"adobe_segment_id": "125", "dp_key_id": "1"}, "type": "adobe"}'
JSON:
{"mapping": {"adobe_segment_id": "125", "dp_key_id": "1"}, "type": "adobe"}
控制器:
@RequestMapping(value = "/insertMapping", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> createUser(@RequestBody RequestBodyDTO mapping) {
LOG.info("/insertMapping" + " ,type:" + mapping.getType().getType());
return null;
}
RequestBodyDTO:
public class RequestBodyDTO {
private MappingDTO mapping;
private TypeDTO type;
public TypeDTO getType() {
return type;
}
public void setType(TypeDTO type) {
this.type = type;
}
public MappingDTO getMapping() {
return mapping;
}
public void setMapping(MappingDTO mapping) {
this.mapping = mapping;
}
}
MappingDTO:
public class MappingDTO {
// adobe
private Integer adobe_segment_id;
private Integer dp_key_id;
public Integer getAdobe_segment_id() {
return adobe_segment_id;
}
public void setAdobe_segment_id(Integer adobe_segment_id) {
this.adobe_segment_id = adobe_segment_id;
}
public Integer getDp_key_id() {
return dp_key_id;
}
public void setDp_key_id(Integer dp_key_id) {
this.dp_key_id = dp_key_id;
}
}
TypeDTO:
public class TypeDTO {
private String type;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
答案 0 :(得分:0)
我更改了#34;私人TypeDTO类型&#34; to&#34;私有字符串类型&#34;。