【发布时间】:2019-01-12 00:05:43
【问题描述】:
我有一个具有以下属性的模型“NewModel”
import com.fasterxml.jackson.databind.JsonNode;
@ApiModel(
description = "Data Class to hold new details"
)
public class NewModel {
@ApiModelProperty(
notes = "Value in JSON key:value format. Can be any key:value pair",
example = "{ds:2017:08:05,hh:11}"
)
private final JsonNode value;
(... getters and setters ...)
}
除此之外,我还有一些在请求正文中获取 JSON 的休息控制器。我使用此模型从请求正文中获取 JSOn。
我已经使用 maven 配置了 springfox swagger,并生成了 api 定义。但是在生成的 API 定义中,这个模型已经生成为
"NewModel": {
"type": "object",
"properties": {
"value": {
"example": "{nds:2017:08:05,hh:11}",
"description": "Value of the stamp in JSON key:value format",
"$ref": "#/definitions/JsonNode"
}
},
"description": "Data Class to hold details"
}
而生成的参考JsonNode定义是
"definitions": {
"JsonNode": {
"type": "object",
"properties": {
"array": {
"type": "boolean"
},
"bigDecimal": {
"type": "boolean"
},
"bigInteger": {
"type": "boolean"
},
"binary": {
"type": "boolean"
},
"boolean": {
"type": "boolean"
},
"containerNode": {
"type": "boolean"
},
"double": {
"type": "boolean"
},
"float": {
"type": "boolean"
},
"floatingPointNumber": {
"type": "boolean"
},
"int": {
"type": "boolean"
},
"integralNumber": {
"type": "boolean"
},
"long": {
"type": "boolean"
},
"missingNode": {
"type": "boolean"
},
"nodeType": {
"type": "string",
"enum": [
"ARRAY",
"BINARY",
"BOOLEAN",
"MISSING",
"NULL",
"NUMBER",
"OBJECT",
"POJO",
"STRING"
]
},
"null": {
"type": "boolean"
},
"number": {
"type": "boolean"
},
"object": {
"type": "boolean"
},
"pojo": {
"type": "boolean"
},
"short": {
"type": "boolean"
},
"textual": {
"type": "boolean"
},
"valueNode": {
"type": "boolean"
}
}
}
现在,当我使用此 API 定义生成客户端库时,客户端允许的 JsonNode 对象只有布尔变量,我无法分配实际的 JSON 字符串到它,因此 无法将 JSON 值传递 到连接服务器(我从中生成 API 定义)
我想知道是否有一种方法可以使用 swagger 生成的库将 Json 字符串从客户端传递到服务器。或者我可以达到所需最终结果的任何其他方向。
感谢(并为长篇文章道歉)
【问题讨论】:
-
遇到类似问题,您有解决办法吗?
标签: json jackson swagger swagger-codegen springfox