Hacker News new | past | comments | ask | show | jobs | submit login

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.



I 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.


Not 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.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.


> 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.


Unless you deserialize into a type whose properties are interface types, in which case you're definitely checking...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: