Comments (17)
@dunglas https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php#L275 same problem ?
from api-platform.
The posted JSON value must be a float (and not an int or a string).
Can you check that you send a float value. If it's ok can you copy your HTTP request here to allow us to debug?
from api-platform.
Sorry my bad, in Nelmio Sandbox everything is send as string
from api-platform.
@dunglas I am using the latest version (2-alpha) and I have the same problem with those values :
{"billingDate":"2016-08-30T09:33:22.917Z","trader":"Restaurant","totalAmount":240}
"The type of the "totalAmount" attribute must be "float", "integer" given."
from api-platform.
@cvernerie can you copy here the HTTP request you sent to the API please?
from api-platform.
POST /notes HTTP/1.1
Host: api.exemple.com
Connection: keep-alive
Content-Length: 69
Pragma: no-cache
Cache-Control: no-cache
accept: application/ld+json
Origin: http://exemple.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36
content-type: application/ld+json
Referer: http://exemple.com/
Accept-Encoding: gzip, deflate
Accept-Language: fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
from api-platform.
@cvernerie the body of the request is missing.
from api-platform.
{"billingDate":"2016-08-30T09:33:22.917Z","trader":"Restaurant","totalAmount":240}
from api-platform.
Here is the problem, totalAmount
is of type "foat" and you send an int. Try this:
{"billingDate":"2016-08-30T09:33:22.917Z","trader":"Restaurant","totalAmount":240.0}
from api-platform.
The problem is that in Javascript you can't cast an int to a float :
parseFloat('200') // == 200
parseFloat('200').toFixed(2) // == '200.00'
parseFloat('200.00') // == 200
from api-platform.
This is indeed a problem. The JSON standard does not differentiate float
and int
. However JSON Schema and XML (as well as JSON-LD) do make the difference.
A possible fix is to handle this case especially: automatically cast to float
when this type is expected and is_numeric
returns true
.
ping @api-platform/core-team
from api-platform.
@cvernerie I've just pushed a patch fixing this, can you test it please? api-platform/core#714
from api-platform.
@cvernerie can you try with the dev-master
version, it should fix the problem.
from api-platform.
@dunglas That works fine, thanks ! :)
from api-platform.
@Shine-neko we should indeed do something for that in Symfony too. It's on my todo list.
from api-platform.
@dunglas ? :)
from api-platform.
Still on my todo list but PRs welcome :)
from api-platform.
Related Issues (20)
- Subresource Identifier
- Validation of path parameters HOT 1
- http instead https docs.jsonld
- Use of property class on APIResource Tag
- Custom Controller via POST accessible, not via GET-Collection
- UniqueEntity not fully working on PUT HOT 3
- Error "Unable to generate an IRI" if id has "." or ":"
- what is the best way to add current user information related to GetCollection request HOT 5
- SwaggerUI shows error: Unable to render this definition HOT 1
- Redundant @context field in OpenAPI for embedded JSON+LD resources
- denormalizationContext imbrique
- New Format : RSS feed
- Open up Paginator::$documents for read
- 502 status code in "Check PWA reachability" ci step
- Specific order of operations in #ApiResource annotation causes incorrect API schema (using wrong serialization group)
- Impossible to use vite/vue3 with supplied Caddyfile HOT 3
- The event_listeners_backward_compatibility_layer: true is broken in version 3.3.0 HOT 1
- Building 3.3.2 for production throws: Error: <Html> should not be imported outside of pages/_document. HOT 3
- "Invalid identifier value or configuration." HOT 1
- ProcessorInterface multiple ProcessorInterfaces (persist & remove) && Security within State Providers
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from api-platform.