GithubHelp home page GithubHelp logo

Comments (2)

wdullaer avatar wdullaer commented on May 26, 2024

I did some investigation into this.
The problem seems to be that internally the json is deserialized into a map[interface{}]interface{}. Since json.Unmarshal has no type information it choses to use float64 to deserialize number values. This is on par with other json implementations.

If you deserialize into a concrete type (say int64), json.Unmarshal will do the right thing and no precision is lost.

Theoretically, if the openapi spec provides detailed type information, we could try to be smarter when deserializing, but I didn't immediately see a quick fix.

from restish.

danielgtaylor avatar danielgtaylor commented on May 26, 2024

Thanks for looking into this. It's a pretty difficult problem for a generic tool to solve. At this point I'm going to say this is expected behavior as so many implementations behave this way.

Also from the JSON RFC:

Note that when such software is used, numbers that are integers and
are in the range [-(2**53)+1, (2**53)-1] are interoperable in the
sense that implementations will agree exactly on their numeric
values.

If you need to send around big numbers a common tactic in JSON is to encode them to strings. Other formats like CBOR have built-in support for big numbers.

from restish.

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.