Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allows JSON type overrides in Decode() #9

Merged
merged 1 commit into from
Nov 10, 2022
Merged

Conversation

oleoneto
Copy link
Owner

With this change, Decode() can take an optional list of Go types and their respective JSON types which it'll use while decoding the provided payload.

Motivation:
By default, Go structs are treated as JSON objects by the jsonschema validator. However, there may be instances when we may want to override the JSON representation of a type. For example, we may have a custom struct that serves as our own abstraction around a numeric type. The type itself may be a bit more complex than a simple int or a float but, much like Go's built-in types, we may still simply want to transit its underlying value as a number and deal with the specifics of the abstraction at the application or API level.

With this change, `Decode()` can take an optional list of Go types and their
respective JSON types which it'll use while decoding the provided payload.

**Motivation:**
By default, Go structs are treated as JSON objects by the jsonschema validator.
However, there may be instances when we may want to override the JSON representation
of a type. For example, we may have a custom struct that serves as our own abstraction
around a numeric type. The type itself may be a bit more complex than a simple `int`
or a `float` but, much like Go's built-in types, we may still simply want to transit
its underlying value as a number and deal with the specifics of the abstraction at the
application or API level.
@oleoneto oleoneto self-assigned this Nov 10, 2022
@oleoneto oleoneto added enhancement New feature or request release Changes that'll be part of a release labels Nov 10, 2022
@oleoneto oleoneto merged commit 67d4922 into main Nov 10, 2022
@oleoneto oleoneto deleted the json-type-overrides branch November 10, 2022 03:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request release Changes that'll be part of a release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant