Title: Float unmarshaled to integer without failure · Issue #225 · google/jsonapi · GitHub
Open Graph Title: Float unmarshaled to integer without failure · Issue #225 · google/jsonapi
X Title: Float unmarshaled to integer without failure · Issue #225 · google/jsonapi
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 ill...
Open Graph 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 f...
X 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 f...
Opengraph URL: https://github.com/google/jsonapi/issues/225
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Float unmarshaled to integer without failure","articleBody":"`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?\n\nTo illustrate what I mean, here is a working example:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n\n\t\"github.com/google/jsonapi\"\n)\n\ntype MyStruct struct {\n\tID int `jsonapi:\"attr,id\"`\n}\n\nfunc main() {\n\tjsonStr := `{\n\t\t\"data\": {\n\t\t\t\"attributes\": {\n\t\t\t\t\"id\": 10.5\n\t\t\t}\n\t\t}\n\t}`\n\tvar s MyStruct\n\tif err := jsonapi.UnmarshalPayload(strings.NewReader(jsonStr), \u0026s); err != nil {\n\t\tfmt.Println(\"Error:\", err)\n\t}\n\tfmt.Println(\"ID:\", s.ID)\n}\n```\n\nThe output shown is:\n```go\nID: 10\n```\n\nI was expecting that `jsonapi.UnmarshalPayload` would instead return an error. Is there a way to enforce that the accepted type must be integer?\n\nMany thanks in advance 🙏","author":{"url":"https://github.com/edisonspencer","@type":"Person","name":"edisonspencer"},"datePublished":"2025-01-14T11:45:07.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/225/jsonapi/issues/225"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:802f5405-e95f-4c65-d76e-fc60ec4e8305 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 84F6:17C847:E8DBB5:12E308B:6992959D |
| html-safe-nonce | a215002cb87f77d5315b7f97ae5c1e3b8d82a6ecbde660854fcf70c15a53f1e6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NEY2OjE3Qzg0NzpFOERCQjU6MTJFMzA4Qjo2OTkyOTU5RCIsInZpc2l0b3JfaWQiOiI2NDM1MjQ1NTA2NzcxOTgxNzI1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | d09086daa9083b60adb57ffccc316e63a5a2e85d5f0d3215acbfbe0048810cb8 |
| hovercard-subject-tag | issue:2786929366 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/google/jsonapi/225/issue_layout |
| twitter:image | https://opengraph.githubassets.com/04a50cae4f3d312fa50ef0efa23d4076ab08aff325184379ed4389690e046ad9/google/jsonapi/issues/225 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/04a50cae4f3d312fa50ef0efa23d4076ab08aff325184379ed4389690e046ad9/google/jsonapi/issues/225 |
| og:image:alt | 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 f... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | edisonspencer |
| hostname | github.com |
| expected-hostname | github.com |
| None | 42c603b9d642c4a9065a51770f75e5e27132fef0e858607f5c9cb7e422831a7b |
| turbo-cache-control | no-preview |
| go-import | github.com/google/jsonapi git https://github.com/google/jsonapi.git |
| octolytics-dimension-user_id | 1342004 |
| octolytics-dimension-user_login | |
| octolytics-dimension-repository_id | 38635217 |
| octolytics-dimension-repository_nwo | google/jsonapi |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 38635217 |
| octolytics-dimension-repository_network_root_nwo | google/jsonapi |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 848bc6032dcc93a9a7301dcc3f379a72ba13b96e |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width