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