Home

Awesome

nullable

This is a POC implementation of a Nullable type that allows knowing whether a field was nullable and/or optional in Go, meant for JSON serialization and deserialization.

It relies on Go generics, but rather than using a custom struct, it relies on a map as its underlying type. The problem with using a struct is that:

Using a map as underlying type allows using nil while still making use of a non-explicit-pointer to a struct.

This is inspired from this post by KumanekoSakura.

See some examples of usage in nullable_test.go.