You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I kept getting the error where I couldn't unmarshal a saved sample data because for some reason it would think Route.Legs is a type of string. I modified the code to test it directly right after getting a response, but still the same issue.
Environment details
Specify the API at the beginning of the title (for example, "Places: ...")
OS type and version
Library version and other environment information
googlemaps.github.io/maps v1.3.2 (the latest)
go version go1.16.5 darwin/amd64
Steps to reproduce
Get []map.Route from valid client request through the Directions API
Marshal the object
Unmarshal the same object
Code example
routes:=getSampleRoutes()
jsonObj, err:=json.MarshalIndent(routes, "", " ")
iferr!=nil {
log.Fatal(err)
}
// At this point, I was able to check that the proper data came through and that the object was marshalled properlyvarnewRoutes []maps.Routeerr=json.Unmarshal(jsonObj, &newRoutes)
iferr!=nil {
log.Fatal(err) // hits error here
}
Stack trace
fatal error: json: cannot unmarshal object into Go struct field Route.legs of type string
The text was updated successfully, but these errors were encountered:
It seems to happen because of the *url.URL-fields in TransitLine, and if so only applies to transit directions. When these fields are set to null in the JSON and unmarshaling again it works.
An example of what the marshaled URLs might look like for those fields:
You can reproduce it by getting directions from "Bergen, Norway" to "Vossevangen, Norway" by transit.
I have simply added this before marshaling to mitigate it as I don't care about those fields for my use case:
for_, route:=rangeroutes {
for_, leg:=rangeroute.Legs {
for_, step:=rangeleg.Steps {
ifstep.TransitDetails!=nil {
step.TransitDetails.Line.URL=nilstep.TransitDetails.Line.Icon=nilstep.TransitDetails.Line.Vehicle.Icon=nil// NOTE: There is also an URL in step.TransitDetails.Line.Agencies
}
}
}
}
Perhaps this is an issue with the unmarshaling code in encoding.go not handling empty/malformed URLs well?
I kept getting the error where I couldn't unmarshal a saved sample data because for some reason it would think Route.Legs is a type of string. I modified the code to test it directly right after getting a response, but still the same issue.
Environment details
Steps to reproduce
Code example
Stack trace
The text was updated successfully, but these errors were encountered: