Closed andeke07 closed 2 years ago
Can you reproduce on play.golang.org with some payload?
Seems like the input may be corrupted but its hard to tell without a standalone example
@andeke07 you are 100% correct. Here's a playground link reproducing the issue. I see two separate issues here:
eventInfo
will not be captured. The reason for this is that we want the data produced in the resulting map to be consistent with the schema of the struct. In your case, for example, we favor having resultMap["eventInfo"]
containing an object of type struct {EventType string}
over a map[string]interface{}
. This prevents us from being able to represent unknown fields.I think it should be resolved, but I wonder what will be the best approach. Changing this behavior at this point will be a breaking change so the default behavior should remain the same. At least until we release a new major version.
@andeke07 @tmm1 how would you feel about adding an additional option to determine whether the resulting map should aim to be schema-consistent, or contain all data?
Actually, I have an even better solution but let's merge the fix for now and open a new issue to discuss over there 🙏
fixed in v1.1.1
I am trying to use this package for a server which will take JSON input and fire off an alert to our monitoring system. I have a fairly simple JSON package:
Within the eventInfo object, I will have an indeterminate number of fields depending on how much info the alert will be providing (hence why I found this package, I am considering everything within "eventInfo" to be "extra metadata" to add to the alert but I won't necessarily know what that info will be when the event is submitted.
I have the following code:
I am submitting a payload to my server with Insomnia however Marshmallow is giving me an error:
Could not unmarshal incoming data from localhost: parse error: syntax error near offset 156 of ': "stuff"...'
I'm not entirely sure why this is happening. I realise that "more": "stuff" is not part of the struct but I was under the impression that would just be ignored when writing it in to the struct, and these values would then be available in the resultant map that also gets produced.
Is this a bug, or am I formatting my JSON incorrectly and/or handling it incorrectly?
Thanks.