| 1 |
package tests |
| 2 |
|
| 3 |
import fmt "fmt" |
| 4 |
|
| 5 |
//easyjson:json |
| 6 |
type CustomMapKeyType struct { |
| 7 |
Map map[customKeyType]int |
| 8 |
} |
| 9 |
|
| 10 |
type customKeyType [2]byte |
| 11 |
|
| 12 |
func (k customKeyType) MarshalJSON() ([]byte, error) { |
| 13 |
return []byte(fmt.Sprintf(`"%02x"`, k)), nil |
| 14 |
} |
| 15 |
|
| 16 |
func (k *customKeyType) UnmarshalJSON(b []byte) error { |
| 17 |
_, err := fmt.Sscanf(string(b), `"%02x%02x"`, &k[0], &k[1]) |
| 18 |
return err |
| 19 |
} |
| 20 |
|
| 21 |
var customMapKeyTypeValue CustomMapKeyType |
| 22 |
|
| 23 |
func init() { |
| 24 |
customMapKeyTypeValue.Map = map[customKeyType]int{ |
| 25 |
{0x01, 0x02}: 3, |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
var customMapKeyTypeValueString = `{"Map":{"0102":3}}` |