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

Add support for directly marshaling arrays and slices to Extended JSON

    • Type: Icon: New Feature New Feature
    • Resolution: Won't Fix
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 0.2.0
    • Component/s: JSON & ExtJSON
    • None
    • Environment:
      arch/linux 64bit
      go: 1.9.2

      The Extended JSON encoder does not support encoding arrays and slices by themselves. The decoder does support decoding JSON arrays into slices. Add support for encoding arrays and slices to a JSON array.

      (original description below)


      What is the best way to build a JSON Producer. My first approach was to make this: 

      // JSONProducer creates a new JSON producer
      JSONProducer() runtime.Producer { 
        return runtime.ProducerFunc(func(writer io.Writer, data interface{})    error { 
          valueWriter, _ := bsonrw.NewBSONValueWriter(writer) enc, _ :=   bson.NewEncoder(valueWriter) 
          return enc.Encode(data)  
        })
      }
      

      First this version seems to work. But it leads to two different errors, that I dont understand.
      1. runtime error: invalid memory address or nil pointer dereference
      2. WriteArray can only write a Array while positioned on a Element or Value but is positioned on a TopLevel

            Assignee:
            rachelle.palmer@mongodb.com Rachelle Palmer
            Reporter:
            karltga Karl Wolffgang
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: