Skip to content

Adds raw value decoding#6

Merged
KyNorthstar merged 4 commits intoproductionfrom
feature/raw-Decodable
Dec 23, 2025
Merged

Adds raw value decoding#6
KyNorthstar merged 4 commits intoproductionfrom
feature/raw-Decodable

Conversation

@KyNorthstar
Copy link
Contributor

@KyNorthstar KyNorthstar commented Dec 23, 2025

Summary

Now Either can be used to decode payloads which encode different types in the same field, without wrapping those fields in "left"/"right" sub-objects.

The decoder now attempts to interpret a single‑value container as the left type, and if that fails, the right type. Of course, if both fail to decode, then a NeitherLeftNorRightValueWasEncoded error is thrown just as always.

Either<String, Int>
{ "value": "foo" }          // decodes to either.left("foo")
{ "value": 42 }             // decodes to either.right(42)

Usage notes

Since this only depends on which types the field can encode as, this will always decode as .left when the left and right types of the Either are the same:

Either<String, String>
{ "value": "foo" }          // decodes to either.left("foo")
{ "value": "baz" }          // decodes to either.left("baz")

Breaking Changes

While this update preserves existing decoding paths while adding an additional path, it does remove an error which might have previously been thrown. In case any users of this library depended on that error to validate encoded data which doesn't match their desired format, this change is considered breaking and requires a MAJOR version bump.

@KyNorthstar KyNorthstar self-assigned this Dec 23, 2025
@KyNorthstar KyNorthstar added the enhancement New feature or request label Dec 23, 2025
Discovered a bug that the tests didn't yet cover
Copy link
Contributor Author

@KyNorthstar KyNorthstar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@KyNorthstar KyNorthstar merged commit 89bdbb8 into production Dec 23, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant