692b98560b
The omitzero tag now respects custom IsZero() methods on types, similar to how encoding/json handles this. Previously, only reflect.Value.IsZero() was used, which ignores user-defined implementations. Fixes #1003 Co-authored-by: Claude <noreply@anthropic.com>
24 lines
717 B
Go
24 lines
717 B
Go
package toml
|
|
|
|
import (
|
|
"encoding"
|
|
"reflect"
|
|
"time"
|
|
)
|
|
|
|
// isZeroer is used to check if a type has a custom IsZero method.
|
|
// This allows custom types to define their own zero-value semantics.
|
|
type isZeroer interface {
|
|
IsZero() bool
|
|
}
|
|
|
|
var (
|
|
timeType = reflect.TypeOf((*time.Time)(nil)).Elem()
|
|
textMarshalerType = reflect.TypeOf((*encoding.TextMarshaler)(nil)).Elem()
|
|
textUnmarshalerType = reflect.TypeOf((*encoding.TextUnmarshaler)(nil)).Elem()
|
|
isZeroerType = reflect.TypeOf((*isZeroer)(nil)).Elem()
|
|
mapStringInterfaceType = reflect.TypeOf(map[string]interface{}(nil))
|
|
sliceInterfaceType = reflect.TypeOf([]interface{}(nil))
|
|
stringType = reflect.TypeOf("")
|
|
)
|