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

Add support for directly marshaling arrays and slices to Extended JSON

    XMLWordPrintableJSON

Details

    • Icon: New Feature New Feature
    • Resolution: Won't Fix
    • Icon: Minor - P4 Minor - P4
    • None
    • 0.2.0
    • JSON & ExtJSON
    • None
    • arch/linux 64bit
      go: 1.9.2

    Description

      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

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: