1

我需要将一个实例映射到Maven 插件用来创建 POJOjava.util.Map的 JSON 模式。org.jsonschema2pojo

我没有找到一个好的和简单的解决方案。

有人可以帮我吗?

这是我实际的 json-schema 文件

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "Response",
    "description": "A Response object",
    "type": "object",
    "properties": {
        "result": {
            "type": "string",
            "description": "describes response status"
        },
        "msg": {
            "type": "string",
            "description": "user msgs"
        }
    },
    "required": ["result"],
    "additionalProperties": false
}

我需要添加一个在 Java"errors"中转换为 a的字段。java.util.Map<String, String>

4

1 回答 1

0

AFAIKadditionalProperties完成了这项工作。您可以声明一个类型的错误属性,Map<String, Object>例如像这样(现在是 yaml):

...
properties:
  errors:
    type: object
    additionalProperties:
      type: object

您无需指定键的类型,因为它描述了一个 json 文档,它自然地将字符串作为对象的键。

如果您有自己的类型作为该映射中的值,那么您也可以执行或引用另一个type: object定义type: stringMap<String, String>

于 2016-08-24T13:44:57.787 回答