Updated generated code in example
This commit is contained in:
parent
dfe6af903e
commit
a77ef8d8e5
@ -7,32 +7,51 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r ShirtSize) MarshalJSON() ([]byte, error) {
|
var (
|
||||||
if s, ok := interface{}(r).(fmt.Stringer); ok {
|
_ShirtSizeNameToValue = map[string]ShirtSize{
|
||||||
return json.Marshal(s.String())
|
"NA": NA,
|
||||||
|
"XS": XS,
|
||||||
|
"S": S,
|
||||||
|
"M": M,
|
||||||
|
"L": L,
|
||||||
|
"XL": XL,
|
||||||
}
|
}
|
||||||
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{
|
_ShirtSizeValueToName = map[ShirtSize]string{
|
||||||
"NA": NA, "XS": XS, "S": S, "M": M, "L": L, "XL": XL,
|
NA: "NA",
|
||||||
}
|
XS: "XS",
|
||||||
|
S: "S",
|
||||||
|
M: "M",
|
||||||
|
L: "L",
|
||||||
|
XL: "XL",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
var v ShirtSize
|
var v ShirtSize
|
||||||
if _, ok := interface{}(v).(fmt.Stringer); ok {
|
if _, ok := interface{}(v).(fmt.Stringer); ok {
|
||||||
_ShirtSizeNameToValue = map[string]ShirtSize{
|
_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 {
|
func (r *ShirtSize) UnmarshalJSON(data []byte) error {
|
||||||
var s string
|
var s string
|
||||||
if err := json.Unmarshal(data, &s); err != nil {
|
if err := json.Unmarshal(data, &s); err != nil {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// generated by jsonenums -type=WeekDay example; DO NOT EDIT
|
// generated by jsonenums -type=WeekDay; DO NOT EDIT
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
@ -7,32 +7,54 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r WeekDay) MarshalJSON() ([]byte, error) {
|
var (
|
||||||
if s, ok := interface{}(r).(fmt.Stringer); ok {
|
_WeekDayNameToValue = map[string]WeekDay{
|
||||||
return json.Marshal(s.String())
|
"Monday": Monday,
|
||||||
|
"Tuesday": Tuesday,
|
||||||
|
"Wednesday": Wednesday,
|
||||||
|
"Thursday": Thursday,
|
||||||
|
"Friday": Friday,
|
||||||
|
"Saturday": Saturday,
|
||||||
|
"Sunday": Sunday,
|
||||||
}
|
}
|
||||||
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{
|
_WeekDayValueToName = map[WeekDay]string{
|
||||||
"Monday": Monday, "Tuesday": Tuesday, "Wednesday": Wednesday, "Thursday": Thursday, "Friday": Friday, "Saturday": Saturday, "Sunday": Sunday,
|
Monday: "Monday",
|
||||||
}
|
Tuesday: "Tuesday",
|
||||||
|
Wednesday: "Wednesday",
|
||||||
|
Thursday: "Thursday",
|
||||||
|
Friday: "Friday",
|
||||||
|
Saturday: "Saturday",
|
||||||
|
Sunday: "Sunday",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
var v WeekDay
|
var v WeekDay
|
||||||
if _, ok := interface{}(v).(fmt.Stringer); ok {
|
if _, ok := interface{}(v).(fmt.Stringer); ok {
|
||||||
_WeekDayNameToValue = map[string]WeekDay{
|
_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 {
|
func (r *WeekDay) UnmarshalJSON(data []byte) error {
|
||||||
var s string
|
var s string
|
||||||
if err := json.Unmarshal(data, &s); err != nil {
|
if err := json.Unmarshal(data, &s); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user