Skip to content

Conversation

@thallgren
Copy link

This change addresses two issues:

  1. The set function previously resolved TextUnmarshaler implementations first, which made it impossible to provide a custom parser for those types using the CustomMap option.
  2. The asTextUnmarshaler function assigned a zero value to a pointer field even when the target value did not implement the TextUnmarshaler interface. Code executed after this call relied on that side effect.

The following changes were made:

  • asTextUnmarshaler was rewritten as textUnmarshalerSet, which sets the value only if the interface is implemented and does nothing otherwise.
  • The code following the former `asTextUnmarshale call was updated to no longer rely on any side effects.
  • The custom parser check was moved to the top of the set function, giving it higher priority than TextUnmarshaler resolution.
  • A TestCustomParserCalledForTextMarshallImpl was added that validates the new functionality.

This change addresses two issues:

1. The `set` function previously resolved `TextUnmarshaler`
   implementations first, which made it impossible to provide a custom
   parser for those types using the `CustomMap` option.
2. The `asTextUnmarshaler` function assigned a zero value to a pointer
   field even when the target value did not implement the
   `TextUnmarshaler` interface. Code executed after this call relied on
   that side effect.

The following changes were made:

- `asTextUnmarshaler` was rewritten as `textUnmarshalerSet`, which sets
  the value only if the interface is implemented and does nothing
  otherwise.
- The code following the former `asTextUnmarshale  call was updated to
  no longer rely on any side effects.
- The custom parser check was moved to the top of the set function,
  giving it higher priority than `TextUnmarshaler` resolution.
- A `TestCustomParserCalledForTextMarshallImpl` was added that validates
  the new functionality.

Signed-off-by: Thomas Hallgren <[email protected]>
@thallgren thallgren changed the title Allow overriding TextUnmarshalers via CustomMap Allow overriding TextUnmarshalers via FuncMap Jan 7, 2026
@thallgren
Copy link
Author

Ping @caarlos0

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant