@@ -81,6 +81,9 @@ type DecoderOptions struct {
8181 // Prefer UnmarshalText over custom types.
8282 PrefUnmarshalText bool
8383
84+ // Disable UnmarshalText interface
85+ DisableUnmarshalText bool
86+
8487 // Ignore unknown form fields. By default unknown fields are an error
8588 // (although all valid keys will still be decoded).
8689 IgnoreUnknownKeys bool
@@ -371,20 +374,27 @@ func (dec *Decoder) traverseInMap(byField bool) {
371374
372375// decode sets the value in the field
373376func (dec * Decoder ) decode () error {
374- // check if has UnmarshalText method or a custom function to decode it
375- if dec .opts .PrefUnmarshalText {
376- if ok , err := dec .isUnmarshalText (dec .curr ); ok || err != nil {
377- return err
378- }
377+ // if DisableUnmarshalText is true then only use customType if available
378+ if dec .opts .DisableUnmarshalText {
379379 if ok , err := dec .isCustomType (); ok || err != nil {
380380 return err
381381 }
382382 } else {
383- if ok , err := dec .isCustomType (); ok || err != nil {
384- return err
385- }
386- if ok , err := dec .isUnmarshalText (dec .curr ); ok || err != nil {
387- return err
383+ // check if has UnmarshalText method or a custom function to decode it
384+ if dec .opts .PrefUnmarshalText {
385+ if ok , err := dec .isUnmarshalText (dec .curr ); ok || err != nil {
386+ return err
387+ }
388+ if ok , err := dec .isCustomType (); ok || err != nil {
389+ return err
390+ }
391+ } else {
392+ if ok , err := dec .isCustomType (); ok || err != nil {
393+ return err
394+ }
395+ if ok , err := dec .isUnmarshalText (dec .curr ); ok || err != nil {
396+ return err
397+ }
388398 }
389399 }
390400
@@ -654,6 +664,8 @@ var (
654664
655665// isUnmarshalText returns a boolean and error. The boolean is true if the
656666// field's type implements TextUnmarshaler, and false if not.
667+ // If the field implements TextUnmarshaler, then it is used to decode the value
668+ // in the field.
657669func (dec * Decoder ) isUnmarshalText (v reflect.Value ) (bool , error ) {
658670 // check if implements the interface
659671 m , ok := v .Interface ().(encoding.TextUnmarshaler )
0 commit comments