I've got a problem using Spring Boot 1.4 and Swagger and Swagger UI. When using @RequestBody parameter is displaying as data type string. This does not seems correct.
@ApiOperation(value = "simple message resource")
@ApiImplicitParams({
@ApiImplicitParam(name = "message", value = "Message to send", required = true, dataType = "com.larmic.springboot.swagger.rest.dto.MessageDto", paramType = "body")
})
@RequestMapping(value = "/api/message", method = RequestMethod.POST,
consumes = {"application/json", "application/xml"})
public void sendMessage(@RequestBody MessageDto message) {
System.out.println("ping");
}
and
@XmlRootElement(name = "MessageDto")
@XmlAccessorType(XmlAccessType.FIELD)
@ApiModel(value = "MessageDto", description = "TODO")
public class MessageDto {
@ApiModelProperty(value = "Message content text", required = true, example = "some demo message")
private String content;
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
I've found a lot of fixes using full name of MessageDto or setting correct value of @ApiModel but nothing seems to work.
I've created a full example here https://github.com/larmic/SpringBootAndSwaggerUI
Maybe someone can help.
The @RequestBody annotation allows us to retrieve the request's body. We can then return it as a String or deserialize it into a Plain Old Java Object (POJO). Spring has built-in mechanisms for deserializing JSON and XML objects into POJOs, which makes this task a lot easier as well.
Simply put, the @RequestBody annotation maps the HttpRequest body to a transfer or domain object, enabling automatic deserialization of the inbound HttpRequest body onto a Java object. Spring automatically deserializes the JSON into a Java type, assuming an appropriate one is specified.
This appears to be a bug in Springfox (#1344). You could work around it by not using @ApiImplicitParams
, but by annoting your method parameter itself with the @ApiParam
annotation:
@ApiOperation(value = "simple message resource")
@RequestMapping(value = "/api/message", method = RequestMethod.POST,
consumes = {"application/json", "application/xml"})
public void sendMessage(@ApiParam(name = "message", value = "Message to send", required = true) @RequestBody MessageDto message) {
System.out.println("ping");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With