Skip to content

Conversation

@Azmisov
Copy link

@Azmisov Azmisov commented Nov 17, 2025

Implements an Unmarshaler interface. This provides similar behavior to UnmarshalJSON, which people are familiar with already from the standard library. It is complementary to DecodeHook. It runs after decode hooks, as though it were simply another specialized outputKind.

  • DecodeHook: Decoder is responsible for decoding all types. Can be composed using various middleware-like function hooks. Powerful, but requires knowing and registering all custom types with the decoder.
  • Unmarshaler: Types have responsibility for decoding themselves. Inversion of responsibility. Often better for abstraction. E.g. Users of a library don't need to know the details of how to decodes all its custom types, instead we just let the Unmarshaler interface abstract that away.

The implementation aims for similar behavior to UnmarshalJSON, e.g. allowing value receivers.

I believe I've got all the essential cases covered by unit tests.

Alternative to #11, which was stale and didn't have proper unit tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant