使用Java进行JSON模式验证 - 参考

4

我正在尝试使用 (https://github.com/fge/json-schema-validator) 架构验证器验证我的 JSON。

  1. 您推荐使用 jackson schema 生成来生成 JSON schema,还是有更好的方法?

  2. 我有一个名为 Location 的对象,其中有一个对象列表(BaseObject)。 我创建了一个引用 BaseObject 的 location 模式。但是验证失败,并显示以下错误信息-["": domain: validation; keyword: properties; message: required property(ies) not found; missing: ["id","refName"]; required: ["id","refName"]]

我在使用引用时是否犯了错误?

Location.json - schema

{
   "type":"object",
   "properties":{
      "locationType":{
         "type":"string"
      },
      "mapsRefs":{
          "$ref": "file://localhost/c:/baseobject.json" 
         }
      }
   }
}

baseobject.json - 模式

{
   "type":"object",
   "properties":{
      "refName":{
         "type":"string",
          "required":true
      },
      "id":{
         "type":"integer",
          "required":true
      },
      "refs":{
         "type":"array",
          "required":false,
         "items":{
            "type":"string"
         }
      }
   }

}

1
在 Location.json 文件中有一个多余的闭合括号。 - Markus Kösel
1个回答

1
回答你的第一个问题,根据我的经验,Jackson是处理Java中JSON最易于使用和文档化的API。
对于第二个问题,您将“id”和“refName”定义为必需属性,您可能正在使用错误的模式进行验证,或者没有传递所需的属性。
这看起来很像GitHub上已关闭的问题: https://github.com/fge/json-schema-validator/issues/22

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接