Comments (3)
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.
@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.
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)
- Making it null safe (Flutter v2 friendly) HOT 9
- Model Issue HOT 1
- Thank you so much for making this. This makes my development so much easier than before. HOT 1
- Code generate missing class
- wrong data type
- Provide support for the Null safety models. HOT 1
- New null safety does not let fromJson method to work HOT 4
- Null safety not support and 'List' constructor is not abiavle HOT 3
- should update? HOT 1
- Sir can you make it for null safety for flutter 2.2.0 HOT 3
- Hey ! are you still alive ? HOT 1
- Missing Parameter type for 'v', HOT 1
- Convert float to int
- All numbers to num instead of double and int? HOT 1
- Hello, is it okay https://javiercbk.github.io/json_to_dart/ set to open? I want to fork a copy
- Error during installation HOT 1
- Unnecessary 'this.' qualifier HOT 1
- Can it be made into windows application so that don't have to open web pages every time.
- ζδΉη¨ HOT 1
- Wrong Type generated
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 json_to_dart.