gpt4 book ai didi

json - 模型类中 JsonNode 属性的 springfox swagger 配置

转载 作者:行者123 更新时间:2023-12-03 00:33:36 25 4
gpt4 key购买 nike

我有一个具有以下属性的模型“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 ...)
}

除此之外,我还有一些休息 Controller ,它们在请求正文中获取 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 对象仅具有 bool 变量,并且我无法分配实际的 JSON 字符串到它,因此无法将 JSON 值传递到连接服务器(我从中生成 API 定义)

我想知道是否有一种方法可以使用 swagger 生成的库将 Json 字符串从客户端传递到服务器。或者我可以实现所需的最终结果的任何其他方向。

谢谢(并对长帖子表示歉意)

最佳答案

ApiModelProperty 中的属性 dataType="java.util.Map" 应该会有所帮助

public class NewModel {
@ApiModelProperty(
example = "{ds:2017:08:05,hh:11}",
dataType = "java.util.Map"
)
private final JsonNode value;

关于json - 模型类中 JsonNode 属性的 springfox swagger 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51683752/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com