Allow overriding TextUnmarshalers via FuncMap#401
Open
thallgren wants to merge 1 commit intocaarlos0:mainfrom
Open
Allow overriding TextUnmarshalers via FuncMap#401thallgren wants to merge 1 commit intocaarlos0:mainfrom
thallgren wants to merge 1 commit intocaarlos0:mainfrom
Conversation
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 <thomas@tada.se>
Author
|
Ping @caarlos0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change addresses two issues:
setfunction previously resolvedTextUnmarshalerimplementations first, which made it impossible to provide a custom parser for those types using theCustomMapoption.asTextUnmarshalerfunction assigned a zero value to a pointer field even when the target value did not implement theTextUnmarshalerinterface. Code executed after this call relied on that side effect.The following changes were made:
asTextUnmarshalerwas rewritten astextUnmarshalerSet, which sets the value only if the interface is implemented and does nothing otherwise.TextUnmarshalerresolution.TestCustomParserCalledForTextMarshallImplwas added that validates the new functionality.