You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi guys,
Have a problem:
initial data: [ { "field1": "Value1", "field2": "Value2 }, { "field1": "Value1", "field2": "Value2 }, .....
Mapping such json - don't have any problem using: Response.map(to: [Custom].self)
But if I have empty root array [ ] - we got "Failed to map data to JSON." But there is no Failing to map. It is just empty array. Is not better to return empty array instead of error? Or maybe I do something wrong and there is another way?
Thanks.
The text was updated successfully, but these errors were encountered:
Hey @edon2005. You are right, in case of an empty JSON you will get an exception. This is because JSONSerialization fails as well in this case. We would have to check if the error is so verbose that we could differentiate empty array vs other errors to return empty array or re-throw an error. But right now it seems like it's not that easy task.
If you want you could investigate the case and present your results in a form of PR/Issue - I would be happy to give you feedback about it. You could also just use do/catch block to return an empty array for exceptions.
I will do PR but i am very junior. So you need to be very careful. Thanks for your framework. It is very cool! Have not realized that you are from Poland. I am too :)
Hi guys,
Have a problem:
initial data:
[ { "field1": "Value1", "field2": "Value2 }, { "field1": "Value1", "field2": "Value2 }, .....
Mapping such json - don't have any problem using: Response.map(to: [Custom].self)
But if I have empty root array
[ ]
- we got "Failed to map data to JSON." But there is no Failing to map. It is just empty array. Is not better to return empty array instead of error? Or maybe I do something wrong and there is another way?Thanks.
The text was updated successfully, but these errors were encountered: