I'm searching for a library which enables me to filter out a json instance in accordance with a json schema. If the json instance contains elements not defined in the schema they should be filtered out. I have found this for JavaScript: https://www.npmjs.org/package/json-schema-filter, but have been unable to find something that does this in Java.
Does anyone have suggestion as to how this can be achieved in Java? Or where to find a library that does the job?
Regards Morten
An example
File schemaname.json:
{
"type": "object",
"properties": {
"aid": {
"type": "string"
}
}
}
final String json =
{
"aid" : "123954",
"newfield" : "itsValue"
}
What I'm asking is if the filterInstance(instance,schema) method shown below exists.
JsonNode schema = JsonLoader.fromResource("path/schemaname.json");
JsonNode instance = (new ObjectMapper()).readTree(json);
JsonNode fInstance = filterInstance(instance,schema);
fInstance =
{
"aid" : "123954"
}