[GODRIVER-1756] cannot decode array into a map[string]* Created: 27/Sep/20  Updated: 27/Oct/23  Resolved: 02/Nov/20

Status: Closed
Project: Go Driver
Component/s: BSON
Affects Version/s: 1.4.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: 滨 黄 Assignee: Isabella Siu (Inactive)
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File customDecoder.go    

 Description   

I am trying to read a K/V into map[string]string, but it reports "cannot decode array into a map[string]string" if the content is empty.

 

The data is written by PHP code, sometimes it has value _

{"hellow": "world"}

, but sometimes it is _[]



 Comments   
Comment by Isabella Siu (Inactive) [ 07/Oct/20 ]

Hi mikehb78@gmail.com,

While it is intentional that arrays cannot be decoded into maps, you can register a custom map decoder that will handle empty arrays, like customDecoder.go

Generated at Thu Feb 08 08:37:04 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.