问题
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