Created
August 16, 2013 22:35
-
-
Save kendellfab/6254073 to your computer and use it in GitHub Desktop.
Handling custom Json marshalling in golang.
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
type Whatever struct { | |
someField int | |
} | |
func (w Whatever) MarshalJSON() ([]byte, error) { | |
return json.Marshal(struct{ | |
SomeField int `json:"some_field"` | |
}{ | |
SomeField: w.someField, | |
}) | |
} | |
func (w Whatever) MarshalJSON() ([]byte, error) { | |
return json.Marshal(map[string]interface{}{ | |
"some_field": w.SomeField, | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment