gpt4 book ai didi

java - 从 JSON Schema 为非对象类型生成 POJO

转载 作者:太空宇宙 更新时间:2023-11-04 14:39:00 25 4
gpt4 key购买 nike

我正在尝试从 XMBC 的 JSON 模式生成 POJO。我用jsonschema2pojo来做到这一点。然而,什么也没有生成。它甚至不会给我带来错误。

这是我尝试生成的简化示例 json 架构:

{
"description": "JSON-RPC API of XBMC",
"id": "http://xbmc.org/jsonrpc/ServiceDescription.json",
"methods": {
"Addons.ExecuteAddon": {
"description": "Executes the given addon with the given parameters (if possible)",
"params": [
{
"name": "addonid",
"required": true,
"type": "string"
},
{
"default": "",
"name": "params",
"type": [
{
"additionalProperties": {
"default": "",
"type": "string"
},
"type": "object"
},
{
"items": {
"type": "string"
},
"type": "array"
},
{
"description": "URL path (must start with / or ?",
"type": "string"
}
]
},
{
"default": false,
"name": "wait",
"type": "boolean"
}
],
"returns": {
"type": "string"
},
"type": "method"
}
},
"notifications": {
"Application.OnVolumeChanged": {
"description": "The volume of the application has changed.",
"params": [
{
"name": "sender",
"required": true,
"type": "string"
},
{
"name": "data",
"properties": {
"muted": {
"required": true,
"type": "boolean"
},
"volume": {
"maximum": 100,
"minimum": 0,
"required": true,
"type": "integer"
}
},
"required": true,
"type": "object"
}
],
"returns": null,
"type": "notification"
}
},
"types": {
"Addon.Content": {
"default": "unknown",
"enums": [
"unknown",
"video",
"audio",
"image",
"executable"
],
"id": "Addon.Content",
"type": "string"
}
},
"version": "6.14.3"
}

我必须承认我对 JSON 的了解非常简洁,也许这只是我的一个简单的错误。但是任何人都可以帮助我如何从这样的 JSON 模式生成 Java 对象吗?

最佳答案

JSON 架构不支持方法。 JSON 模式定义了 json 数据结构,它不会用于定义您的方法。 JSON 模式中最重要的属性是 properties

从 JSON 模式生成 POJO 数据模型很好,但不是业务逻辑。您可以从those examples了解JSON模式.

关于java - 从 JSON Schema 为非对象类型生成 POJO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25197197/

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