[GODRIVER-2407] BSON Unmarshal to struct uses incorrect type alias for interface{} Created: 04/May/22 Updated: 28/Oct/23 Resolved: 27/May/22 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | BSON |
| Affects Version/s: | 1.9.1 |
| Fix Version/s: | 1.10.0, 1.10.0-beta1 |
| Type: | Bug | Priority: | Unknown |
| Reporter: | Thomas Chandelle | Assignee: | Preston Vasquez |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
SummaryI'm trying to unmarshal some document received from mongo into a struct. This struct has a member that is a map[string]interface but with an alias (type metadata map[string]interface{} {}in the example below). This map can contains any data, including other map[string]interface{}{}. When unmarshalling the document, it's correctly parsing this member as type metadata, but it's also converting map that are included in the map as this the type metadata. I think it should be map[string]interface instead. Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).1.9.1 How to Reproducehttps://go.dev/play/p/baefmEyupxI Unmarshal as {{main.data{Metadata:main.metadata{"foo":main.metadata {"bar":"baz"}}}}} But expected as {{main.data{Metadata:main.metadata{"foo":map[string]interface {} {"bar":"baz"}}}}} Additional BackgroundPlease provide any additional background information that may be helpful in diagnosing the bug. |
| Comments |
| Comment by Preston Vasquez [ 27/May/22 ] | ||||||||||||||||||||||||||||||||||
|
thomas.chandelle@gmail.com , thank you for bringing this to the teams attention. We have introduced a work-around intended to default empty types into either primitive.M or primitive.D. It’s worth noting that there is no encodable value for a “BSON Map”; all maps are encoded as embedded documents. In your case, since the “embedded map” is an empty interface, we can only tell the decoder to default it to primitive.M or primitive.D. This logic will be available next week after the version 1.10.0 release. Here is an example of the usage:
| ||||||||||||||||||||||||||||||||||
| Comment by Githook User [ 26/May/22 ] | ||||||||||||||||||||||||||||||||||
|
Author: {'name': 'Preston Vasquez', 'email': 'prestonvasquez@icloud.com', 'username': 'prestonvasquez'}Message: Co-authored-by: Benjamin Rewis <32186188+benjirewis@users.noreply.github.com> Co-authored-by: Benjamin Rewis <32186188+benjirewis@users.noreply.github.com> | ||||||||||||||||||||||||||||||||||
| Comment by Preston Vasquez [ 17/May/22 ] | ||||||||||||||||||||||||||||||||||
|
thomas.chandelle@gmail.com Thank you for bringing this to our attention! The team has begun looking into the issue. |