go-toml icon indicating copy to clipboard operation
go-toml copied to clipboard

Fix UnmarshalTOML is not called when its underlying type is an array

Open ImSingee opened this issue 1 year ago • 5 comments

This PR is for v1.

This resolves the issue where, if a type implements toml.Unmarshaler but it has an array as its underlying type, the UnmarshalTOML method won't be triggered.

ImSingee avatar May 19 '23 06:05 ImSingee

Hi! Thank you for the patch! However v1 is not supported anymore and will not receive any update. Consider using go-toml v2 instead.

pelletier avatar May 19 '23 14:05 pelletier

@pelletier Thanks for yor reminder. You can close this PR at your opinion.

I’m not using v2 (in fact, I just downgraded to v1 today) because and only because of the lack of missing toml.Unmarshaler interface.

Though there’s TextUnmarshaler, but it can only handle string fields. However, I want to (and need to) do more for historical reasons. The case is just that we have a field that needs to accept both a string and a string array. But in v2, there’s no way to implement it.

Is it possible to re-add the toml.Unmarshaler interface? It will do increase flexibility. And if you accept the feature, I can submit a PR to implement that.

ImSingee avatar May 19 '23 14:05 ImSingee

Makes sense. I'd be happy to see a good patch to implement toml.Unmarshaler for v2! I think it would also help others (https://github.com/pelletier/go-toml/issues/857).

pelletier avatar May 19 '23 14:05 pelletier

@pelletier 👀 Okay, I will try to implement it!

ImSingee avatar May 19 '23 14:05 ImSingee

@ImSingee created https://github.com/pelletier/go-toml/issues/873 with some thoughts on the topic, hopefully it's helpful!

pelletier avatar May 19 '23 15:05 pelletier