mailru / easyjson

Fast JSON serializer for golang.
MIT License
4.48k stars 421 forks source link

fails to correctly encode non-pointer structures. #19

Closed james-lawrence closed 8 years ago

james-lawrence commented 8 years ago
package main

import (
    "encoding/json"
    "fmt"
)

//go:generate easyjson -snake_case example.go

//easyjson:json
type obj struct {
    Field1 string
    Field2 string
}

func main() {
    var (
        buffer []byte
        err    error
    )
    details := obj{
        Field1: "foo",
        Field2: "bar",
    }

    if buffer, err = json.Marshal(details); err != nil {
        fmt.Println("marshal error", err)
        return
    }

    fmt.Println("bad", string(buffer))

    if buffer, err = json.Marshal(&details); err != nil {
        fmt.Println("marshal error", err)
        return
    }

    fmt.Println("good", string(buffer))
}
james-lawrence commented 8 years ago

looks like someone already has a PR fixing this: https://github.com/mailru/easyjson/pull/15