-
Notifications
You must be signed in to change notification settings - Fork 461
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
57f5c33
commit 36513d4
Showing
1 changed file
with
19 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,25 @@ | ||
package stripe | ||
|
||
import "encoding/json" | ||
|
||
type Application struct { | ||
ID string `json:"id"` | ||
Name string `json:"name"` | ||
} | ||
|
||
// UnmarshalJSON handles deserialization of an Application. | ||
// This custom unmarshaling is needed because the resulting | ||
// property may be an id or the full struct if it was expanded. | ||
func (a *Application) UnmarshalJSON(data []byte) error { | ||
type application Application | ||
var aa application | ||
err := json.Unmarshal(data, &aa) | ||
if err == nil { | ||
*a = Application(aa) | ||
} else { | ||
// the id is surrounded by "\" characters, so strip them | ||
a.ID = string(data[1 : len(data)-1]) | ||
} | ||
|
||
return nil | ||
} |