GithubHelp home page GithubHelp logo

Comments (17)

Shine-neko avatar Shine-neko commented on May 21, 2024 2

@dunglas https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php#L275 same problem ? :trollface:

from api-platform.

dunglas avatar dunglas commented on May 21, 2024

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.

marcin-piela avatar marcin-piela commented on May 21, 2024

Sorry my bad, in Nelmio Sandbox everything is send as string

from api-platform.

cvernerie avatar cvernerie commented on May 21, 2024

@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.

dunglas avatar dunglas commented on May 21, 2024

@cvernerie can you copy here the HTTP request you sent to the API please?

from api-platform.

cvernerie avatar cvernerie commented on May 21, 2024

@dunglas

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.

dunglas avatar dunglas commented on May 21, 2024

@cvernerie the body of the request is missing.

from api-platform.

cvernerie avatar cvernerie commented on May 21, 2024

@dunglas

{"billingDate":"2016-08-30T09:33:22.917Z","trader":"Restaurant","totalAmount":240}

from api-platform.

dunglas avatar dunglas commented on May 21, 2024

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.

cvernerie avatar cvernerie commented on May 21, 2024

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.

dunglas avatar dunglas commented on May 21, 2024

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.

dunglas avatar dunglas commented on May 21, 2024

@cvernerie I've just pushed a patch fixing this, can you test it please? api-platform/core#714

from api-platform.

dunglas avatar dunglas commented on May 21, 2024

@cvernerie can you try with the dev-master version, it should fix the problem.

from api-platform.

cvernerie avatar cvernerie commented on May 21, 2024

@dunglas That works fine, thanks ! :)

from api-platform.

dunglas avatar dunglas commented on May 21, 2024

@Shine-neko we should indeed do something for that in Symfony too. It's on my todo list.

from api-platform.

Shine-neko avatar Shine-neko commented on May 21, 2024

@dunglas ? :)

from api-platform.

dunglas avatar dunglas commented on May 21, 2024

Still on my todo list but PRs welcome :)

from api-platform.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.