This repository was archived by the owner on Jul 22, 2024. It is now read-only.
Support decoding into reflect.Value instances#25
Closed
cbroglie wants to merge 1 commit intomitchellh:masterfrom
Closed
Support decoding into reflect.Value instances#25cbroglie wants to merge 1 commit intomitchellh:masterfrom
cbroglie wants to merge 1 commit intomitchellh:masterfrom
Conversation
This is useful if you have a generic method which is trying to decode
a slice of structs individually. Since you can't pass an object of type
[]myStruct to a method expecting []interface{}, the only way to handle
it is to have the method signature accept just interface{}, and use
reflect to access the individual elements.
cbroglie
pushed a commit
to cbroglie/goamz
that referenced
this pull request
Mar 16, 2015
This has the following benefits: - Can directly translate from map -> struct without relying on JSON marshal/unmarshal - Can unmarshal into addressable reflect.Value objects Note: this depends on mitchellh/mapstructure#25 being accepted before this can/should be merged upstream
Author
|
@mitchellh Any thoughts on this change? I only ask because I'm working on a change to goamz which depends on it. Thanks. |
cbroglie
pushed a commit
to cbroglie/goamz
that referenced
this pull request
Apr 5, 2015
Haven't received any word on mitchellh/mapstructure#25, but using the cbroglie fork will allow this PR to be merged.
|
👍 |
|
Hey @mitchellh , we were using @cbroglie fork to handle github.com/spf13/viper decoding, but it's not compatible with the latest viper version. Do you plan on merging this PR ? Otherwise we'd need to rebase the fork on the latest version of mapstructure. |
Owner
|
This should be possible using hooks and there hasn't been much noise in recent years on this so I'm going to close for now but if this continues to be an issue I'm happy to take a look. Apologies that this slipped through. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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 is useful if you have a generic method which is trying to decode a slice of structs individually. Since you can't pass an object of type
[]myStructto a method expecting[]interface{}, the only way to handle it is to have the method signature accept justinterface{}, and use reflect to access the individual elements.