AddInterfaceKey adds an interface{} to be encoded, must be used inside an object as it will encode a key
(key string, value interface{})
| 90 | |
| 91 | // AddInterfaceKey adds an interface{} to be encoded, must be used inside an object as it will encode a key |
| 92 | func (enc *Encoder) AddInterfaceKey(key string, value interface{}) { |
| 93 | switch vt := value.(type) { |
| 94 | case string: |
| 95 | enc.AddStringKey(key, vt) |
| 96 | case bool: |
| 97 | enc.AddBoolKey(key, vt) |
| 98 | case MarshalerJSONArray: |
| 99 | enc.AddArrayKey(key, vt) |
| 100 | case MarshalerJSONObject: |
| 101 | enc.AddObjectKey(key, vt) |
| 102 | case int: |
| 103 | enc.AddIntKey(key, vt) |
| 104 | case int64: |
| 105 | enc.AddIntKey(key, int(vt)) |
| 106 | case int32: |
| 107 | enc.AddIntKey(key, int(vt)) |
| 108 | case int16: |
| 109 | enc.AddIntKey(key, int(vt)) |
| 110 | case int8: |
| 111 | enc.AddIntKey(key, int(vt)) |
| 112 | case uint64: |
| 113 | enc.AddIntKey(key, int(vt)) |
| 114 | case uint32: |
| 115 | enc.AddIntKey(key, int(vt)) |
| 116 | case uint16: |
| 117 | enc.AddIntKey(key, int(vt)) |
| 118 | case uint8: |
| 119 | enc.AddIntKey(key, int(vt)) |
| 120 | case float64: |
| 121 | enc.AddFloatKey(key, vt) |
| 122 | case float32: |
| 123 | enc.AddFloat32Key(key, vt) |
| 124 | default: |
| 125 | if vt != nil { |
| 126 | enc.err = InvalidMarshalError(fmt.Sprintf(invalidMarshalErrorMsg, vt)) |
| 127 | return |
| 128 | } |
| 129 | return |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | // AddInterfaceKeyOmitEmpty adds an interface{} to be encoded, must be used inside an object as it will encode a key |
| 134 | func (enc *Encoder) AddInterfaceKeyOmitEmpty(key string, v interface{}) { |