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

Add support for directly marshaling arrays and slices to Extended JSON

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Won't Fix
    • Affects Version/s: 0.2.0
    • Fix Version/s: None
    • Component/s: JSON & ExtJSON
    • Labels:
      None
    • Environment:
      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

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

              Dates

              Created:
              Updated:
              Resolved: