Everit schema builder includes unset properties as null

安稳与你 提交于 2020-12-15 05:42:57

问题


Trying to build and use the Schema object:

        Schema rootSchema = ObjectSchema.builder()
                .additionalProperties(true)
                .build();

It seems to work fine until I try to serialize it as a string and then to reload using the SchemaLoader:

        String json = objectMapper.writeValueAsString(rootSchema);
        JSONObject schemaObject = new JSONObject(json);
        Schema schema = SchemaLoader.load(schemaObject);

The problem is that the unset keywords are serialized as null:

{
  "title" : null,
  "description" : null,
  "id" : null,
  "propertySchemas" : { },
  "schemaOfAdditionalProperties" : null,
  "requiredProperties" : [ ],
  "minProperties" : null,
  "maxProperties" : null,
  "propertyDependencies" : { },
  "schemaDependencies" : { },
  "patternProperties" : { }
}

The SchemaLoader reports these as errors, e.g. "java.lang.RuntimeException: org.json.JSONException: JSONObject["id"] not a string." Would it be possible to skip these keywords?

Another problem: the serialized version doesn't include the additionalProperties keyword.

Also, is it possible to include additional keywords, not specified in the JSON Schema spec? AFAIIK the spec itself doesn't prohibit such keywords, and some libraries such as AJV actually use them?

来源:https://stackoverflow.com/questions/64571965/everit-schema-builder-includes-unset-properties-as-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!