Support custom IsZero() methods with omitzero tag (#1020)
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>
This commit is contained in:
@@ -6,10 +6,17 @@ import (
|
||||
"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("")
|
||||
|
||||
Reference in New Issue
Block a user