Skip to content
This repository has been archived by the owner on Dec 4, 2019. It is now read-only.

Unmarshaling JSON into embedded structs doesn't work #27

Open
collinvandyck opened this issue Aug 23, 2018 · 0 comments
Open

Unmarshaling JSON into embedded structs doesn't work #27

collinvandyck opened this issue Aug 23, 2018 · 0 comments

Comments

@collinvandyck
Copy link

This test tries to deserialize JSON input into a struct which embeds another. There are two parts to this test:

  1. use normal encoding/json
  2. use objconv/json

The test fails on the objconv part:

import (
	"encoding/json"
	"testing"

	convjson "github.com/segmentio/objconv/json"
)

func TestObjConv(t *testing.T) {
	type inner struct {
		Value int64
	}
	type outer struct {
		inner
	}
	input := `{"value":42}`

	var res outer
	err := json.Unmarshal([]byte(input), &res)
	if err != nil {
		t.Fatal(err)
	}
	if res.Value != int64(42) {
		t.Fatal(res.Value)
	}

	res = outer{}
	err = convjson.Unmarshal([]byte(input), &res)
	if err != nil {
		t.Fatal(err)
	}
	if res.Value != int64(42) {
		t.Fatal(res.Value)
	}
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant