type Alpha struct {
Name string `json:"name"`
SkipWhenMarshal string `json:"skipWhenMarshal"`
}
func MarshalJSON(out interface{}){
json.Marshal(out)
}
Is it possible to ignore the SkipWhenMarshal field when I do json.Marshal but not when I do json.Unmarshal. It should work for any type who calls MarshalJSON
What you want simply cannot be done with encoding/json.
But you can have two types
Use
AlphaIn
to deserialise JSON with encoding/json.Unmarshal and useAlphaOut
to serialise a struct with encoding/json.Marshal to JSON.Now this alone would be absolute painful to work with but: struct tags do not play a role in convertibility between types which lets you convert from AlphaIn to AlphaOut with a simple type conversion:
(A saner naming scheme would be
Alpha
andAlphaToJSON
or soemthing like this.)