Schemas and rules
A schema lists the properties an entity exposes. A rule per property decides, per instance, whether it is visible and whether it may be written.
A companion that provides it
The companion object extends SchemaProvider and declares a nested class Schema. property selects a property type-safely through a macro from scala-reflect.
Only what the schema lists
With a schema, a property that is not listed is neither serialized nor deserialized, even with @JsonbProperty. Without a rule argument, DefaultRule applies: visible, but read-only.
- DefaultRule[E]
- Visible, never writable. The default.
- DefaultWritableRule[E]
- Visible and writable.
- VisibilityRule[E]
- Your own rule: isVisible and isWriteable per instance and property.
Decisions per instance
A rule sees the instance and the property. It is created through the inject function, so it can take constructor dependencies such as the current user.
A property the rule hides is left out of the JSON entirely, and a property it does not allow to write is ignored silently when it arrives. Clients never see an error for it.