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

时间:2014-08-08 06:24:56

标签: java json code-generation jsonschema

我正在尝试从XMBC的JSON Schema生成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对象吗?

1 个答案:

答案 0 :(得分:0)

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

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

相关问题