Accept equivalent integer references in model responses

This commit is contained in:
2026-11-17 04:22:20 +00:00
parent 2d93e8ae7c
commit 44c767f285
10 changed files with 52 additions and 27 deletions

View File

@@ -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) {