Created
December 18, 2018 12:55
-
-
Save mvantellingen/d3fa9e6d78922c3dcd89365abe7b8f88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (obj *ScopedPrice) UnmarshalJSON(data []byte) error { | |
type Alias ScopedPrice | |
if err := json.Unmarshal(data, (*Alias)(obj)); err != nil { | |
return err | |
} | |
if obj.Value != nil { | |
obj.Value = mapDiscriminatorTypedMoney(obj.Value) | |
} | |
return nil | |
} | |
func mapDiscriminatorTypedMoney(input interface{}) TypedMoney { | |
discriminator := input.(map[string]interface{})["type"].(string) | |
switch discriminator { | |
case "centPrecision": | |
new := CentPrecisionMoney{} | |
mapstructure.Decode(input, &new) | |
return new | |
} | |
return nil | |
} | |
// Insert the type = centPrecision value in the generated JSON | |
func (obj CentPrecisionMoney) MarshalJSON() ([]byte, error) { | |
type Alias CentPrecisionMoney | |
return json.Marshal(struct { | |
Type string `json:"type"` | |
*Alias | |
}{ | |
Type: "centPrecision", | |
Alias: (*Alias)(&obj) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment