Convert the Template
field to json.RawMessage in a MarshalJSON method on BrandTemplate
.
type BrandTemplate struct {
Type string `json:"type"` // Template type (e.g., email_forgot_password)
Locale string `json:"locale"` // Locale (e.g., "es" for Spanish, "en" for English)
Template string `json:"-"` // Template content (Email/SMS content)
}
func (t *BrandTemplate) MarshalJSON() ([]byte, error) {
// Define type to break recursive calls to MarshalJSON.
// The type X has all of fields for BrandTemplate, but
// non of the methods.
type X BrandTemplate
// Marshal a type that shadows BrandTemplate.Template
// with a raw JSON field of the same name.
return json.Marshal(
struct {
*X
Template json.RawMessage `json:"template"`
}{
(*X)(t),
json.RawMessage(t.Template),
})
}