Table of Contents
Why JSON Schema support is needed?
APEX PDP uses AVRO library to perform JSON encoding and decoding to serialize/deserialize the data it consumes. When doing so, it attempts to ensure that the JSON data conforms to the AVRO Schema provided.
In an event that triggers a policy, there could be some fields that are optional, the fields which are not always present depending on the use case.
Avro fails to handle this, and there is no way in APEX-PDP to handle events with optional fields today.
...
Hence, adding JSON Schema support in addition to Avro support in APEX-PDP can be beneficial.
In addition to the support for optional fields, JSON Schema support can help in writing the schema and using the fields in the logic itself much more simple and straightforward.
What are the potential solutions?
The JSON Schema validators available today are listed here: https://json-schema.org/implementations.html#validator-java
Medeia-validator seems to be the sensible choice to be used for the JSON Schema support. Medeia-validator is already part of the policy-common/policy-models modules.
medeia-validator-gson supports GSON under the hood making it the right choice. The performance of this library also seems to be better comparitively as per the analysis here https://github.com/worldturner/medeia-validator#performance
What are the expected changes?
1) In the codebase
A new maven module plugins-context-schema-json will be added here: https://github.com/onap/policy-apex-pdp/tree/master/plugins/plugins-context/plugins-context-schema
This module will most likely make use of medeia-validator-gson library to encode and decode Json events.
Note: If using medeia-validator-gson library, there shouldn't be much need for implementation specific mapper classes as it uses GSON under the hood and the conversion is more straightforward.
...
Code Block | ||
---|---|---|
| ||
var payloadEntry = new java.util.HashMap(); payloadEntry.put("create-subscription-properties", payloadProperties) var payload = new java.util.HashMap(); payload.put("create-subscription-request", payloadEntry); |
Summary
JsonSchema support in APEX-PDP has the following advantages:
...