将映射转换为json模式

时间:2016-05-27 07:41:37

标签: jsonschema

我想创建以下的json架构:

我的java pojo看起来像:

public class Filter {

    Map<String, Object> 
    Map<String, Integer> sort;
    int offset = -1;
    int limit = -1;
    List<String> responseFields;
}

我的样本json看起来像:

{
  "terms": {
    "foo":"bar",
    "foo1":1
  },
  "sort": {
    "foo": 1
  },
  "offset": 1,
  "limit": 25,
  "responseFields": ["foo", "foo1"]
}

我坚持为条款和订单字段创建json-schema。谁能告诉我怎样才能模仿这个?

1 个答案:

答案 0 :(得分:0)

可以使用Map<String, ???>来描述

{ "type": "object", "additionalProperties": ??? }

{
  "type": "object",
  "properties": {
    "terms": { "type": "object" },
    "sort": {
      "type": "object",
      "additionalProperties": { "type": "integer" }
    },
    "offset": { "type": "integer" },
    "limit": { "type": "integer" },
    "responseFields": {
      "type": "array",
      "items": { "type": "string" }
    }
  }
}