mapstructure icon indicating copy to clipboard operation
mapstructure copied to clipboard

How to ignore / bypass a field in a struct which I don't own / no control?

Open tigerinus opened this issue 2 years ago • 1 comments

Hello,

I need to decode the a JSON supposed to be the type (ProxyTransport) from the frp project:

https://github.com/fatedier/frp/blob/v0.52.3/pkg/config/v1/proxy.go#L40

Its field BandwidthLimit is expected to be of type types.BandwidthQuantity.

But the actual value is an empty string ""

I don't own this project. I don't want to clone the struct and keep maintaining it.

Is there a way to bypass this field so the rest of the struct can be decoded?

Thanks!

tigerinus avatar Nov 14 '23 11:11 tigerinus

Did you try creating a custom DecoderConfig with a DecodeHookFuncValue? You could check the source type and return a default value for this specific field, for all other fields just return the source value directly.

rashmi-tondare avatar Jan 11 '24 07:01 rashmi-tondare