Updated generated code in example

This commit is contained in:
Francesc Campoy 2015-02-04 13:40:08 +00:00
parent dfe6af903e
commit a77ef8d8e5
2 changed files with 72 additions and 31 deletions

View File

@ -7,32 +7,51 @@ import (
"fmt"
)
func (r ShirtSize) MarshalJSON() ([]byte, error) {
if s, ok := interface{}(r).(fmt.Stringer); ok {
return json.Marshal(s.String())
}
s, ok := map[ShirtSize]string{
NA: "NA", XS: "XS", S: "S", M: "M", L: "L", XL: "XL",
}[r]
if !ok {
return nil, fmt.Errorf("invalid ShirtSize: %d", r)
}
return json.Marshal(s)
var (
_ShirtSizeNameToValue = map[string]ShirtSize{
"NA": NA,
"XS": XS,
"S": S,
"M": M,
"L": L,
"XL": XL,
}
var _ShirtSizeNameToValue = map[string]ShirtSize{
"NA": NA, "XS": XS, "S": S, "M": M, "L": L, "XL": XL,
_ShirtSizeValueToName = map[ShirtSize]string{
NA: "NA",
XS: "XS",
S: "S",
M: "M",
L: "L",
XL: "XL",
}
)
func init() {
var v ShirtSize
if _, ok := interface{}(v).(fmt.Stringer); ok {
_ShirtSizeNameToValue = map[string]ShirtSize{
interface{}(NA).(fmt.Stringer).String(): NA, interface{}(XS).(fmt.Stringer).String(): XS, interface{}(S).(fmt.Stringer).String(): S, interface{}(M).(fmt.Stringer).String(): M, interface{}(L).(fmt.Stringer).String(): L, interface{}(XL).(fmt.Stringer).String(): XL,
interface{}(NA).(fmt.Stringer).String(): NA,
interface{}(XS).(fmt.Stringer).String(): XS,
interface{}(S).(fmt.Stringer).String(): S,
interface{}(M).(fmt.Stringer).String(): M,
interface{}(L).(fmt.Stringer).String(): L,
interface{}(XL).(fmt.Stringer).String(): XL,
}
}
}
func (r ShirtSize) MarshalJSON() ([]byte, error) {
if s, ok := interface{}(r).(fmt.Stringer); ok {
return json.Marshal(s.String())
}
s, ok := _ShirtSizeValueToName[r]
if !ok {
return nil, fmt.Errorf("invalid ShirtSize: %d", r)
}
return json.Marshal(s)
}
func (r *ShirtSize) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {

View File

@ -1,4 +1,4 @@
// generated by jsonenums -type=WeekDay example; DO NOT EDIT
// generated by jsonenums -type=WeekDay; DO NOT EDIT
package main
@ -7,32 +7,54 @@ import (
"fmt"
)
func (r WeekDay) MarshalJSON() ([]byte, error) {
if s, ok := interface{}(r).(fmt.Stringer); ok {
return json.Marshal(s.String())
}
s, ok := map[WeekDay]string{
Monday: "Monday", Tuesday: "Tuesday", Wednesday: "Wednesday", Thursday: "Thursday", Friday: "Friday", Saturday: "Saturday", Sunday: "Sunday",
}[r]
if !ok {
return nil, fmt.Errorf("invalid WeekDay: %d", r)
}
return json.Marshal(s)
var (
_WeekDayNameToValue = map[string]WeekDay{
"Monday": Monday,
"Tuesday": Tuesday,
"Wednesday": Wednesday,
"Thursday": Thursday,
"Friday": Friday,
"Saturday": Saturday,
"Sunday": Sunday,
}
var _WeekDayNameToValue = map[string]WeekDay{
"Monday": Monday, "Tuesday": Tuesday, "Wednesday": Wednesday, "Thursday": Thursday, "Friday": Friday, "Saturday": Saturday, "Sunday": Sunday,
_WeekDayValueToName = map[WeekDay]string{
Monday: "Monday",
Tuesday: "Tuesday",
Wednesday: "Wednesday",
Thursday: "Thursday",
Friday: "Friday",
Saturday: "Saturday",
Sunday: "Sunday",
}
)
func init() {
var v WeekDay
if _, ok := interface{}(v).(fmt.Stringer); ok {
_WeekDayNameToValue = map[string]WeekDay{
interface{}(Monday).(fmt.Stringer).String(): Monday, interface{}(Tuesday).(fmt.Stringer).String(): Tuesday, interface{}(Wednesday).(fmt.Stringer).String(): Wednesday, interface{}(Thursday).(fmt.Stringer).String(): Thursday, interface{}(Friday).(fmt.Stringer).String(): Friday, interface{}(Saturday).(fmt.Stringer).String(): Saturday, interface{}(Sunday).(fmt.Stringer).String(): Sunday,
interface{}(Monday).(fmt.Stringer).String(): Monday,
interface{}(Tuesday).(fmt.Stringer).String(): Tuesday,
interface{}(Wednesday).(fmt.Stringer).String(): Wednesday,
interface{}(Thursday).(fmt.Stringer).String(): Thursday,
interface{}(Friday).(fmt.Stringer).String(): Friday,
interface{}(Saturday).(fmt.Stringer).String(): Saturday,
interface{}(Sunday).(fmt.Stringer).String(): Sunday,
}
}
}
func (r WeekDay) MarshalJSON() ([]byte, error) {
if s, ok := interface{}(r).(fmt.Stringer); ok {
return json.Marshal(s.String())
}
s, ok := _WeekDayValueToName[r]
if !ok {
return nil, fmt.Errorf("invalid WeekDay: %d", r)
}
return json.Marshal(s)
}
func (r *WeekDay) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {