【发布时间】:2020-06-19 16:20:27
【问题描述】:
我正在尝试为我的 POST Api 创建 Body-parameter(JSON),这是一个 JSON 请求。我只有 JSON Schema 。我正在尝试列出不同的 JSON 测试数据,涵盖正流和负流。
是否有任何选项可以使用 Java 以编程方式生成/创建 JSON 数据? .我附上了一个小的 Json 模式(只是为了理解目的),但我的实际模式更复杂,有很多 Array's 和 Nested Json's 。
我的 Json 架构:
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "http://example.com/example.json",
"type": "object",
"title": "The Root Schema",
"description": "The root schema comprises the entire JSON document.",
"required": [
"FirstName",
"LastName",
"Age",
"Interest"
],
"properties": {
"FirstName": {
"$id": "#/properties/FirstName",
"type": "string",
"title": "The Firstname Schema",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"Vijay"
]
},
"LastName": {
"$id": "#/properties/LastName",
"type": "string",
"title": "The Lastname Schema",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"Karthik"
]
},
"Age": {
"$id": "#/properties/Age",
"type": "integer",
"title": "The Age Schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
30
]
},
"Interest": {
"$id": "#/properties/Interest",
"type": "array",
"title": "The Interest Schema",
"description": "An explanation about the purpose of this instance.",
"default": [],
"items": {
"$id": "#/properties/Interest/items",
"type": "string",
"title": "The Items Schema",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"Food",
"movie",
"Learning",
"VideoGames"
]
}
}
}
}enter code here
我的 TestData 看起来像:
{
"FirstName":"Vivi",
"LastName":"Karrri",
"Age":30,
"Interest":["Food","movie","Learning","VideoGames"]
}
任何建议我们如何才能实现这一目标? 注意:我正在使用 Springboot,并且请求对象有完整的 POJO
【问题讨论】:
-
Karthikeyan 你得到这个问题的解决方案了吗,我也遇到了同样类型的问题,如果你找到了解决方案,请告诉我..
标签: java spring-boot api automation qa