Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsonpb: Cannot unmarshal string into float or double #649

Closed
kyleconroy opened this issue Jul 5, 2018 · 2 comments
Closed

jsonpb: Cannot unmarshal string into float or double #649

kyleconroy opened this issue Jul 5, 2018 · 2 comments

Comments

@kyleconroy
Copy link

With the following protocol buffer file

syntax = "proto3";
package example
option go_package = "example"

message Foo {
  float bar = 1;
}

I would expect this test to pass.

package twitter

import (
	"strings"
	"testing"

	"github.com/golang/protobuf/jsonpb"
	"github.com/kyleconroy/example"
)

const foo = `
{"bar": "1.0"}
`

func TestLoadFloat(t *testing.T) {
	m := jsonpb.Unmarshaler{}
	f := example.Foo{}
	if err := m.Unmarshal(strings.NewReader(foo), &f); err != nil {
		t.Fatal(err)
	}
}

It does not

--- FAIL: TestLoadFlaot (0.00s)
	foo_test.go:26: json: cannot unmarshal string into Go value of type float32

The language guide suggests that floats and doubles should be supported as strings.

JSON value will be a number or one of the special string values "NaN", "Infinity", and "-Infinity". Either numbers or strings are accepted. Exponent notation is also accepted.

@jhump
Copy link
Contributor

jhump commented Jul 6, 2018

@kyleconroy, are you sure you have the latest version of the repo checked out? I am pretty sure this issue was recently addressed: #630

@kyleconroy
Copy link
Author

That was the problem, as I was using v1.10. When can we expect another release?

@golang golang locked and limited conversation to collaborators Jun 26, 2020
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

2 participants