Comments (3)
@peterwvj I'll have a look a it.
from openfoodfacts-dart.
@peterwvj I don't know how satisfactory it could be, but this is how you could "fix" the bug:
test('ProductPackaging bug', () {
final testProduct = Product();
const productName = 'Orange';
testProduct.productName = productName;
testProduct.packagings = [ProductPackaging()..quantityPerUnit = '75cl'];
final productJson = testProduct.toJson();
final String jsonString = jsonEncode(productJson); // HERE
try {
final productRestored =
Product.fromJson(jsonDecode(jsonString) as Map<String, dynamic>); // and HERE
expect(productRestored.productName, productName);
} catch (e, s) {
print(s);
fail('Could not restore Product from JSON ${e.toString()}');
}
});
Not sure why it works with the json encode/decode steps.
But it does work in Smoothie anyway: for our background tasks we have to encode/decode products into strings.
Feel free to close the issue if relevant.
from openfoodfacts-dart.
@monsieurtanuki thanks for looking into this and sorry for not getting back any sooner.
I think the problem is the JSON generation of the packagins
fields. After looking a bit more into this, I tried assigning a "toJson" conversion function to the packagings
field and that made the test pass. This approach is similar to the way JSON conversion is implemented for the ingredients
fields (which is also implemented using a List
).
After adding the proposed fix, I did run into some issues regenerating the *.g.dart files using build_runner
but I managed to fix that by upgrading the SDK dependencies according to the instructions described here.
I submitted the changes with PR #762. Could you take a look and let me know what you think?
from openfoodfacts-dart.
Related Issues (20)
- Being able to check off, obf, opf and opff
- OBF OPF OPFF currently incompatible with api v3
- Refactoring: move Taxonomy methods to a specific file
- Localize traces
- Possible language & Country specification confusion HOT 2
- OpenFoodAPIConfiguration.globalUriProductHelper ? HOT 3
- Default productName and languages HOT 2
- Add product field "lc" as "product main language" HOT 1
- tracesTagsInLanguages always empty HOT 2
- Add preferred language and country field retrieval and editability HOT 1
- Some small fails HOT 2
- Cannot login with a non-ASCII username HOT 3
- Adding support for the Prices project HOT 7
- Implement the new ElasticSearch search endpoint HOT 1
- "No server response" error: to be localized and with reusable URL
- /search HOT 1
- Separate Project for Search-a-licious Dart SDK with Integration in OpenFoodFacts-Dart HOT 1
- Add a `copyWith` method to the `Product` object HOT 4
- `getProductImageIds` fails when there is no `product->images` in the json
- Missing nutrients (e.g. Polyols) HOT 8
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 openfoodfacts-dart.