Accept equivalent integer references in model responses
This commit is contained in:
@@ -2,10 +2,22 @@
|
||||
package jsonnumber
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Integer accepts exact JSON integer values within the native integer range.
|
||||
type Integer int
|
||||
|
||||
func (n *Integer) UnmarshalJSON(raw []byte) error {
|
||||
if value, ok := Int(string(raw)); ok {
|
||||
*n = Integer(value)
|
||||
return nil
|
||||
}
|
||||
return json.Unmarshal(raw, (*int)(n))
|
||||
}
|
||||
|
||||
// Int accepts lexical integers and equivalent decimal and exponent spellings
|
||||
// in the native integer range. value must be a valid JSON number token.
|
||||
func Int(value string) (int, bool) {
|
||||
|
||||
Reference in New Issue
Block a user