4 ms·
I'm not sure exaclty what he's talking about with Serde, in Go when you deserialize data into a struct it is strongly typed. It's not up to the dev to check tha
by Thaxll 3y ago
I'm not sure exaclty what he's talking about with Serde, in Go when you deserialize data into a struct it is strongly typed. It's not up to the dev to check that you received a string or an int.
- steveklabnik 3y agoI have not done deserialization in Go, but my understanding of what he meant via context was that because everything has default values, it is possible to end up with a struct even if the JSON (or whatever) isn't actually well-formed. I don't know how true that is or to what extent it causes issues.
- Thaxll 3y agoNot to my knowledge, for example if it's json data, if the json is malformed it will error out, if you have etra field you can error out as well: https://pkg.go.dev/encoding/json#Decoder.DisallowUnknownFields https://pkg.go.dev/encoding/json#Decoder.DisallowUnknownFiel... For input that does not have the fields of the destination well you can use other libraries that check that for you or use pointers.
- deleted 3y ago[deleted]
- steveklabnik 3y ago> For input that does not have the fields of the destination well you can use other libraries Right, this is what I was thinking, but that this is the case is the point being made here, and it's consistent with the rest of the post. The default option doesn't really check things for you.
- nunez 3y agoUnless you deserialize into a type whose properties are interface types, in which case you're definitely checking...