▲ | physicles 3 days ago | |
Love seeing meaningful stdlib improvements. I just ran our full suite of a few thousand unit tests with GOEXPERIMENT=jsonv2 and they all passed. (well, one test failed because an error message was changed, but that's on us) I'm especially a fan of breaking out the syntactic part into into its own jsontext package. It makes a ton of sense, and I could see us implementing a couple parsers on top of that to get better performance where it really matters. I wish they would take this chance to ditch omitempty in favor of just the newly-added omitzero (which is customizable with IsZero()), to which we'll be switching all our code over Real Soon Now. The two tags are so similar that it takes effort to decide between them. | ||
▲ | kbolino 2 days ago | parent [-] | |
I think the "omitempty" tag name might be too tarnished to keep around, but I think the distinction made between its redefined meaning and the new "omitzero" tag in v2 is quite useful: - "omitempty" will omit an object field after encoding it, according to its JSON value - "omitzero" will omit an object field before encoding it, according to its Go value The former is particularly useful when you are dealing with foreign types that don't implement IsZero (yet) or implement it in an inappropriate way for how you're using it. You could, of course, write a wrapper type, but even when you can use struct embedding to make the wrapper less painful, you still have to duplicate all of the constructors/factories for that type, and you have to write the tedious code to do the conversions somewhere. |