-
-
Notifications
You must be signed in to change notification settings - Fork 177
Closed
Description
Here is the minimum program which demonstrates the bug:
package main
import (
rdb "github.com/dancannon/gorethink"
"log"
)
type Custom int
func (Custom) MarshalJSON() ([]byte, error) {
return []byte(`"MarshalJSON -- BUG HERE!1!"`), nil
}
type Nested struct {
Test CustomStruct
}
type CustomStruct struct {
InStruct Custom
}
func main() {
session, err := rdb.Connect(rdb.ConnectOpts{Address: "localhost:28015"})
if err != nil {
log.Fatalln(err.Error())
}
rdb.DBDrop("test_db").RunWrite(session)
rdb.DBCreate("test_db").RunWrite(session)
rdb.DB("test_db").TableCreate("test").RunWrite(session)
var val Custom = 123
rdb.DB("test_db").Table("test").Insert(&Nested{
Test: CustomStruct{InStruct: val}}).RunWrite(session)
rdb.DB("test_db").Table("test").Insert(
map[string]interface{}{"Test": map[string]interface{}{"InMap": val}}).RunWrite(session)
}The output:
{
"Test": {
"InStruct": 123
} ,
"id": "f0f77db2-9124-45ce-9c08-f5cbc1e82d78"
} {
"Test": {
"InMap": "MarshalJSON -- BUG HERE!1!"
} ,
"id": "f3b10b8f-ded9-41b2-bce7-f762ef250493"
}This time I got the latest version of gorethink, so the bug is real :)
The basic difference from the example I gave earlier is the inner map declaration:
map[string]interface{} vs map[string]Custom