昂首阔步@ApiModel值被忽略

时间:2018-08-03 18:21:24

标签: spring-boot swagger

使用springfox-swagger 2.8.0,我们在Spring Boot应用程序中有一个POJO:

@ApiModel(value = "Receipt")
public class Receipt {

    @ApiModelProperty(position = 0) 
    private String guid;

    public Receipt(String guid) {
        this.guid = guid;
    }

    public String getGuid() {
        return guid;
    }
}

我们希望将其转换为JSON,如下所示:

"Receipt": {
     "guid":"86f3426c-f200-4bc2-b8e9-e55d6e2c9969"
 }

但它缺少包装器值,并且仅显示为:

{"guid":"86f3426c-f200-4bc2-b8e9-e55d6e2c9969"}

编辑:

控制器:

@RestController
@RequestMapping("/packages")
@EnableHypermediaSupport(type = HypermediaType.HAL)
public class PackageController {
    @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<Receipt> sendPackage(@RequestBody FooPackage fooPackage) {
        String guid = getGUID();

        // ...

        Receipt receipt = new Receipt(guid);
        BodyBuilder builder = ResponseEntity.ok();
        return builder.body(receipt);
}

0 个答案:

没有答案