-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] <title> #86
Comments
ps. I tried changing the name of the file from If it is useful here is the generated CustomerShop class whenever the error happens: class CustomerShop {
CustomerShop();
factory CustomerShop.fromJson(Map<String, dynamic> json) {
// TODO: implement fromJson
throw UnimplementedError('CustomerShop.fromJson($json) is not implemented');
}
Map<String, dynamic> toJson() {
// TODO: implement toJson
throw UnimplementedError();
}
} |
@madatr Hi 👋 and thank you for your very detailed report. By working with multiple JSON in one file you need to be careful. I see some bad practice. Given your example, you need to wrap your JSON to the list 👇 [ // <- Start of the list body.
{
"__className": "customer_shop",
//...
},
{
"__className": "customer_profile",
//...
}
] // // <- End of the list body. Don't do that 👇 /** BAD */
[
{
"__className": "location", // <- Location object
"__path": "/lib/models/",
"laitidude": 0.1,
"longitude": 0.1
},
{
"__className": "customer_profile",
"__path": "/lib/models/",
"location": {} // <- same Location object in the same map.
//...
}
]
/** GOOD */
[
{
"__className": "customer_profile",
"__path": "/lib/models/",
"location": { // <- put here instead Location.
"laitidude": 0.1,
"longitude": 0.1
}
//...
}
] Object naming 👇 /** BAD */
[
{
"__className": "customer_profile", // <- Required class name because the JSON object does not have a keyword.
"location": { // <- This object has a keyword.
"__className": "location", // <- Do not add a class name to an object with keys.
"laitidude": 0.1,
"longitude": 0.1
}
//...
}
]
/** GOOD */
[
{
"__className": "customer_profile", // <- There's only one name per object.
"location": {
"laitidude": 0.1,
"longitude": 0.1
}
//...
}
] Try to upgrade your JSON and tell us about the problems you are facing 😉 |
Hi @iamarnas thank you for the quick reply and for the nice tips, I just started using your package and in fact jsonc only today. If I find the time I may contribute some time to add to the documentation of this package for newbies like me. I followed your recommendations for the json but it still gives me the error and not generate any class file whenever I set the location to required. (I did try both ways) so I guess it may be a bug after all. Here is the snippet if you'd like to try and replicate the issue: [{
"__className": "customer_profile", // <- The base class name of the object.
"__path": "/lib/models/", // <- override default path with a new one by adding '__path' key.
"r@applicationUserId": 18,
"r@block": false,
"r@username": "+962700000000",
"r@name": "TESTUSER",
"r@phoneNumber": "+962700000000",
"[email protected]_shop": [
{
"r@shopId": 5,
"r@name": "shopName",
"r@location": {
"r@latitude": 0.1,
"r@longitude": 0.1
},
"phoneNumber": "0787383510",
"r@shopCategory": "shopcategory"
}
]
}] |
@madatr I will look at this when I will find a time. For now you can generate without |
Take your time, already did :) |
Is there an existing issue for this?
Current Behavior
Hi, Firstly thank you so much for this super package/extension, its very useful.
I think I came across a strange bug when using r@ annotation in the .jsonc file.
When trying to create a class that has a required value object the script fails (does not generate the corresponding file) and return the following error:
![Screenshot 2022-03-18 at 10 00 59](https://user-images.githubusercontent.com/45605051/158953821-6cfbfae4-0e5f-4671-8f1e-9d4773a98eab.png)
Strangely when trying to create a class that has a required list of objects it works flawlessly.
Please find the attached screenshots of some trials that I did:
Expected Behavior
that the required object files are generated
Steps To Reproduce
I am using Json Serialisable.
Version
Relevant JSON syntax
Anything else?
No response
The text was updated successfully, but these errors were encountered: