You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The toml packages behaves unexpectedly when using the TextMarshaler interface. In particular, the toml package ignores a MarshalText implementation if the receiver is a pointer but the value to be serialized is not, like in the following example.
type Document struct {
Field IntSlice
}
type IntSlice []int
func (items *IntSlice) MarshalText() ([]byte, error) {
...
}
I've tried to setup a complete example here: https://go.dev/play/p/tMLzMg5sqTe. The json package, IMHO correctly, makes use of the MarshalText defined as above. Changing the signature like below is required to make the toml package use the custom MarshalText function.
Decoding interface is not affected by this problem, i.e. an UnmarshalText function is picked even if it has a pointer type receiver (tested locally, not shown in the example code).
The text was updated successfully, but these errors were encountered:
I took a quick look, and encoding/json contains some additional code to handle this, in newTypeEncoder(). Need to look a bit at how that works and adjust Encoder.encoder accordingly here.
To set expectations: I probably won't have time for this in the next few weeks, but I'll review patches if you feel like taking a crack at it.
The toml packages behaves unexpectedly when using the TextMarshaler interface. In particular, the toml package ignores a MarshalText implementation if the receiver is a pointer but the value to be serialized is not, like in the following example.
I've tried to setup a complete example here: https://go.dev/play/p/tMLzMg5sqTe. The json package, IMHO correctly, makes use of the MarshalText defined as above. Changing the signature like below is required to make the toml package use the custom MarshalText function.
Decoding interface is not affected by this problem, i.e. an UnmarshalText function is picked even if it has a pointer type receiver (tested locally, not shown in the example code).
The text was updated successfully, but these errors were encountered: