This repository was archived by the owner on Sep 4, 2025. It is now read-only.

Description
jsonapi.UnmarshalPayload seems to cast a float value to integer rather than failing. Keep in mind that the struct it will be unmarshaled into is expecting the value to be an integer rather than a float. Is this expected behaviour?
To illustrate what I mean, here is a working example:
package main
import (
"fmt"
"strings"
"github.com/google/jsonapi"
)
type MyStruct struct {
ID int `jsonapi:"attr,id"`
}
func main() {
jsonStr := `{
"data": {
"attributes": {
"id": 10.5
}
}
}`
var s MyStruct
if err := jsonapi.UnmarshalPayload(strings.NewReader(jsonStr), &s); err != nil {
fmt.Println("Error:", err)
}
fmt.Println("ID:", s.ID)
}
The output shown is:
I was expecting that jsonapi.UnmarshalPayload would instead return an error. Is there a way to enforce that the accepted type must be integer?
Many thanks in advance 🙏