[英]Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException
Please help me out find my error from my title
请帮我找出标题中的错误
@RestController
@RequestMapping("/client")
public class TestController {
@PostMapping(produces = { "application/json", "application/xml" })
public ResponseEntity<Client> createCustomer(@RequestBody Client customer) {
System.out.println("Creat Customer: " + customer);
return ResponseEntity.ok(customer);
}
}
Try this if you have a "normal" spring web mvc. 如果您有一个“普通” spring web mvc,请尝试此操作。
@RequestMapping(value="client", produces = { "application/json", "application/xml" })
public @ResponseBody Customer createCustomer(
@RequestParam Customer customer) {
...do some work like customerDao.create(customer);
System.out.println("Create Customer: " + customer);
return customer;
}
If this is a REST-Interface then you need to first deserialize your incoming data. 如果这是REST接口,则需要首先反序列化传入的数据。 If your data is xml you can do it eg with a JAXB2-Marshaller.
如果您的数据是xml,则可以使用JAXB2-Marshaller进行。 If you have JSON-data you can use FasterXML(Jackson) in the same way.
如果您具有JSON数据,则可以以相同方式使用FasterXML(Jackson)。 Your code could look like
您的代码可能看起来像
@RequestMapping(value="client", produces = { "application/json", "application/xml" })
public @ResponseBody Customer createCustomer(
@RequestBody String body) {
Source source = new StreamSource(new StringReader(body));
RestRequest restRequest = (RestRequest)jaxb2Marshaller.unmarshal(source);
Customer customer = (Customer) restRequest.getRequestData();
...do some work like customerDao.create(customer);
System.out.println("Create Customer: " + customer);
return customer;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.