-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support capturing nested unknown fields #15
Comments
After resolving 12, this playground link produces the following output:
meaning, nested object fields contain concrete structs instead of Here, I presented a possible solution to optionally require all nested objects in the map to be maps as well. After thinking about it again I'm not sure this is very usable. Let's take @andeke07 use case presented here, to iterate the result, _ := marshmallow.Unmarshal(body, &incoming)
data := result["eventInfo"]
dataMap, ok := data.(map[string]interface{})
if ok {
for key := range dataMap {
// ...
}
} Since we have to lookup and cast, this is not aligning with what Marshmallow tries to provide. type IncomingMessage struct {
AlertSummary string `json:"alert_summary" validate:"required"`
DetailedDescription string `json:"detailed_description" validate:"required"`
DeviceName string `json:"deviceName" validate:"required"`
EventMetaData *EventMetaData `json:"eventInfo" validate:"required"`
Options struct {
AffectedCi string `json:"affected_ci"`
AffectedArea string `json:"affected_area"`
HelpURL string `json:"help_url"`
} `json:"options"`
}
type EventMetaData struct {
EventType string `json:"eventType" validate:"required"`
}
func (e *EventMetaData) HandleJSONData(data map[string]interface{}) {
for key := range data {
// ...
}
} |
@andeke07 would that be convenient/usable? |
@avivpxi thanks for this and also sorry for not replying on my other issue - I was away and not getting any email updates so I missed it. That looks like an interesting approach. So unknown fields in the root of the JSON would show up in the produced map, and unknown nested fields would be acted on via this method? |
@andeke07 no worries 😎 Any other ideas? |
@andeke07, this is resolved in v1.1.2 |
Following the discussion on this issue, we want to be able to capture unknown fields in nested objects.
The text was updated successfully, but these errors were encountered: