Git Product home page Git Product logo

Comments (3)

javiercbk avatar javiercbk commented on September 23, 2024

Hi, thanks for your report. Can you share an example of the json that is triggering the fail? It will be easier for me to check what is failing and what can be done...thank you

from json_to_dart.

binod-techindustan avatar binod-techindustan commented on September 23, 2024

@javiercbk I have been using this conversion for my app since beginning. Sometime the backend returns different data type mainly like instead of String we are getting int or reverse. So it cause exception and break the whole process of parsing. So basically I want is whenever such exception occurs I just want to assign a value like null instead of failing whole process.

from json_to_dart.

javiercbk avatar javiercbk commented on September 23, 2024

Let me see if I am understanding correctly.

Currently you are generating your dart classes using this tool with this sample json:

{
  "strProp": "server sends a string here"
}

So you generate your parser and things are looking good, until one day the you get this json:

{
  "strProp": 123
}

The code generated by this library will throw an exception whenever you attempt to parse an int as a string.

If this is currently your problem, and forgive me if I am not understanding correctly, then you have bigger problems.

I doubt that any library can handle an API contract change (in this case sending an int instead of a string).

You can grab those properties you know might change their type to dynamic and remove any parsing related. The downside is that you will end up checking the type every time you need to use such value.

Aside from that, I'm really out of ideas. Although this library is prepared to make type hinting and some other nice stuff, I found myself with little time to keep on adding features to something that currently gets a developer 80% close to the goal of parsing json.

This library generates code that aims to be performant because I use it to generate parsers for my mobile applications, I could have added some type assertion and do my best to save you from these cases, but that would make things:

  • Less performant
  • A mess to write and read
  • If you have an int and suddenly a string arrives, then I'm either force to throw an exception or fail silently which would be much worse
  • For most APIs this use case is useless
  • I would have to pour days of work that might will save a developer's 2 minutes of work.

Did I nailed on the issue? If I did, what ideas do you have for solving this issue for future users?

Thanks

from json_to_dart.

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.