java - Everit 架构构建器将未设置的属性包括为 null
问题描述
尝试构建和使用 Schema 对象:
Schema rootSchema = ObjectSchema.builder()
.additionalProperties(true)
.build();
在我尝试将其序列化为字符串然后使用 SchemaLoader 重新加载之前,它似乎工作正常:
String json = objectMapper.writeValueAsString(rootSchema);
JSONObject schemaObject = new JSONObject(json);
Schema schema = SchemaLoader.load(schemaObject);
问题是未设置的关键字被序列化为null:
{
"title" : null,
"description" : null,
"id" : null,
"propertySchemas" : { },
"schemaOfAdditionalProperties" : null,
"requiredProperties" : [ ],
"minProperties" : null,
"maxProperties" : null,
"propertyDependencies" : { },
"schemaDependencies" : { },
"patternProperties" : { }
}
SchemaLoader 将这些报告为错误,例如“java.lang.RuntimeException: org.json.JSONException: JSONObject["id"] not a string”。是否可以跳过这些关键字?
另一个问题:序列化版本不包含附加属性关键字。
此外,是否可以包含 JSON Schema 规范中未指定的其他关键字?AFAIIK 规范本身并不禁止此类关键字,而 AJV 等一些库实际上使用它们?
解决方案
推荐阅读
- ruby-on-rails - How to find or update a record though a nested attributes form (Rails 6)
- azure - 如何将 Kusto 查询与 2 个表列进行比较?
- html - How to offset for scrollbar width with css?
- python - Unable to install pycryptodome-3.3.1.tar.gz
- blazor - Use different layout in lazy loaded assembly
- javascript - AJAX POST not sending request to express.js server with body-parser due CORS problem (SOLVED)
- visual-studio - Asynchronous callback not working in VSTS/Azure DevOps
- kubernetes - Cert-Manager: renewing dns01 certificate not working
- html - Angular10 响应式表单验证模糊和提交
- django - TypeError:“发布”对象不可调用