[GODRIVER-762] Add support for directly marshaling arrays and slices to Extended JSON Created: 12/Jan/19  Updated: 12/Oct/20  Resolved: 12/Oct/20

Status: Closed
Project: Go Driver
Component/s: JSON & ExtJSON
Affects Version/s: 0.2.0
Fix Version/s: None

Type: New Feature Priority: Minor - P4
Reporter: Karl Wolffgang Assignee: Rachelle Palmer
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
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



 Comments   
Comment by Rachelle Palmer [ 12/Oct/20 ]

We are closing this request for a new feature as there does not seem to be sufficient user demand. To upvote this feature for future consideration by our product team, please upvote here.

Comment by Kristofer Brandow (Inactive) [ 14/Jan/19 ]

Hi karltga,

It looks like we don't currently support encoding slices and arrays to Extended JSON yet. For the runtime errors, try checking the error returns and ensure that you aren't getting an error.

--Kris

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