-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
json: cannot unmarshal array into Go struct field Attribute.attributes.values of type structpb.Value #1019
Comments
|
@puellanivis Thanks for that information, this makes a lot of sense. I'm assuming this means I just need to use the protobuf jsonpb.Unmarshal() instead? I've been looking at it and am having a little trouble understanding in what way I need to change my code because the arguments seem to be a bit different than what the encoding/json unmarshal wants. Would you be able to shed some light on this for me? |
The You would likely need to use something like:
And then |
Thanks for the help, I'm probably gonna move forward with that json.RawMessage and if I run into further problems I may just need to set the entire thing as a protobuf message |
What version of protobuf and what language are you using?
Protobuf version 1.3.2
Go version 1.13.5
What did you do?
I am working with the Google My Business API and I am attempting to retrieve the JSON response of a location.
https://developers.google.com/my-business/reference/rest/v4/accounts.locations/get
After retrieving the JSON, I am unmarshaling it as a Location object. This Location object contains an
attribute
field which is an array of Attribute objects. Within the attribute object is another array of protobuf Values.In my Go code, I have a .go file containing all of the structs which make up this
Location
struct. In this file I am importing the following:And when I define this
Attribute
struct I define theValues
with the following:The JSON that I am receiving from the GMB API contains the following attributes component:
The function in which I am receiving this JSON and unmarshaling is:
What did you expect to see?
If this code was working correctly, my function would correctly unmarshal the JSON into a Location object and it would print out the name of the Location as specified in the JSON.
What did you see instead?
Instead, I am receiving the following error:
Which fails at the
panic(err)
line when unmarshaling.Anything else we should know about your project / environment?
I am running this locally using the GoLand IDE
The text was updated successfully, but these errors were encountered: