mapstructure icon indicating copy to clipboard operation
mapstructure copied to clipboard

Mapping bool gives error "expected type 'bool', got unconvertible type 'string'"

Open dan-lind opened this issue 6 years ago • 2 comments

I have a field in my JSON that looks like this AllowedOAuthFlowsUserPoolClient: true which I want to map to this field AllowedOAuthFlowsUserPoolClient *bool type:"boolean"``

This gives me the error * 'AllowedOAuthFlowsUserPoolClient' expected type 'bool', got unconvertible type 'string'

What should the value be, if not true ?

dan-lind avatar Dec 03 '18 08:12 dan-lind

Do you have "weak types" enabled on the mapstructure config? (Or are using WeakDecode)?

I'm going to keep this open regardless because I think that pointers directly to the correct type shouldn't require weak types, since they're a common pattern in Go to also set whether it was set or not at all.

mitchellh avatar Dec 03 '18 16:12 mitchellh

I "solved" it using weak types, but like you already mentioned I thought this wouldn't/shouldn't be needed here since the correct type was already given as input.

dan-lind avatar Dec 11 '18 19:12 dan-lind