jsonx-org / schema

"JSON Schema Definition" (JSD) language that offers a vocabulary to describe the structure and constraining the contents of JSON documents.
https://jsonx.org/schema/
MIT License
4 stars 1 forks source link

Custom property/member-level bindings: type, field, encode, decode #2

Closed safris closed 4 years ago

safris commented 4 years ago

Currently, the JSONx schema does not provide an ability for the definition of custom bindings at the property/member level. Specifically, the schema does not concern itself with the way a binding framework may represent the boolean, number, string, object, and array types. To the JSONx schema, this information is irrelevant. However, to the binding framework, it would be useful if such knowledge was able to be assigned at the schema level so as to allow users to easily define the specific binding types, decode and encode rules, and/or alternate field mappings.

An example use-case to illustrate the usefulness of this feature would be an object property that represents a Iso8601 date as a string. Without an ability to assign a binding type at the schema level, the user is stuck with this field being nothing more than a string. If the user wants to convert this string to a Date or Instant, he would have to do this with logic on top of the bound Jx object.

Alternatively, if the JSONx schema supported an ability to assign an alternate type and encode/decode rules, this functionality could be fully handled by the Jx binding itself. All the user would do is assign to his iso8601 property:

  1. A type representing either Date or Instant.
  2. A decode rule that would consume a String and produce a Date or Instant.
  3. An encode rule that would consume Date or Instant and produce a String.