Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-713

Remove string key restriction for Encoder and Decoder lookups

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 0.3.0
    • Affects Version/s: None
    • Component/s: BSON
    • None

      The LookupEncoder and LookupDecoder methods on bsoncodec.Registry prevent looking up a default codec for maps with non-string keys. While the default map encoder and decoder does not support non-string keys, users who wish to do so should be able to register their own default encoder and decoder for maps with non-string keys. Users can already register a default map encoder or decoder that handles non-string keys.

      Remove the check from LookupEncoder and LookupDecoder that prevents returning the default map encoder or decoder if the map's key is not a string.

       

      (original description below)


      Why bson package cannot resolve map[int]int, while encoding/json and mgo can.

      https://github.com/globalsign/mgo/pull/140

       

      I wrote a MapEncoder for myself, then call RegisterDefaultEncoder(). It is stuck in

       (r *Registry) LookupEncoder(t reflect.Type) (ValueEncoder, error) {

      ...

      if t != nil && t.Kind() == reflect.Map && t.Key().Kind() != reflect.String

      { ... }

      I cannot implement a mapEncoder/Decoder without modifying this driver.

      Please support numeric map keys.

            Assignee:
            divjot.arora@mongodb.com Divjot Arora (Inactive)
            Reporter:
            825335693@qq.com zhengyang zhu
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: