Closed mmatczuk closed 8 years ago
Hey @mmatczuk, unfortunately we can't implement custom json.{Marshaler,Unmarshaler} for ClientState, as this change would break existing code (e.g. we encode ClientState in JSON and store it internaly in DB, after update the values wouldn't be decoded anymore). Moreover this would open surface for other PRs e.g. regarding missing xml.Marshaler, yaml.Marshaler or other encodings, which I don't think should be done in the tunnel library.
The best solution that I strongly encourage is to write your own models and enums, and keep the encoding logic there - this way you'd have full control over the encoding/decoding.
type YourModel struct {
...
State TunnelState
...
}
type TunnelState tunnel.ClientState
var (
TunnelUnknown = tunnel.ClientUnknown
TunnelStarted = tunnel.ClientStarted
...
)
func (t TunnelState) MarshalJSON() ([]byte, error) { ... }
func (t TunnelState) UnmarshalJSON([]byte) error { ... }
func (t TunnelState) MarshalBinary() ([]byte, error) { ... }
func (t TunnelState) UnmarshalBinary([]byte) error { ... }
...
WDYT?
Braking any code is not worth adding this change. Please close this request. Thanks for advise, this is actually what I did before sending PR.
@mmatczuk 👍
ClientState json Marshaller and UnMarshaller implementation generated using https://github.com/campoy/jsonenums.