@@ -17,7 +17,7 @@ import (
|
||||
|
||||
var (
|
||||
mapperValueType = reflect.TypeOf((*MapperValue)(nil)).Elem()
|
||||
boolMapperType = reflect.TypeOf((*BoolMapper)(nil)).Elem()
|
||||
boolMapperValueType = reflect.TypeOf((*BoolMapperValue)(nil)).Elem()
|
||||
jsonUnmarshalerType = reflect.TypeOf((*json.Unmarshaler)(nil)).Elem()
|
||||
textUnmarshalerType = reflect.TypeOf((*encoding.TextUnmarshaler)(nil)).Elem()
|
||||
binaryUnmarshalerType = reflect.TypeOf((*encoding.BinaryUnmarshaler)(nil)).Elem()
|
||||
@@ -47,6 +47,12 @@ type MapperValue interface {
|
||||
Decode(ctx *DecodeContext) error
|
||||
}
|
||||
|
||||
// BoolMapperValue may be implemented by fields in order to provide custom mappings for boolean values.
|
||||
type BoolMapperValue interface {
|
||||
MapperValue
|
||||
IsBool() bool
|
||||
}
|
||||
|
||||
type mapperValueAdapter struct {
|
||||
isBool bool
|
||||
}
|
||||
@@ -194,7 +200,7 @@ func (r *Registry) ForType(typ reflect.Type) Mapper {
|
||||
for _, impl := range []reflect.Type{typ, reflect.PtrTo(typ)} {
|
||||
if impl.Implements(mapperValueType) {
|
||||
// FIXME: This should pass in the bool mapper.
|
||||
return &mapperValueAdapter{impl.Implements(boolMapperType)}
|
||||
return &mapperValueAdapter{impl.Implements(boolMapperValueType)}
|
||||
}
|
||||
}
|
||||
// Next, try explicitly registered types.
|
||||
|
||||
Reference in New Issue
Block a user