Skip to content
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

Root Array #53

Open
edon2005 opened this issue Mar 22, 2018 · 2 comments
Open

Root Array #53

edon2005 opened this issue Mar 22, 2018 · 2 comments

Comments

@edon2005
Copy link

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.

@sunshinejr
Copy link
Owner

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.

Let me know if it make sense 😉

@edon2005
Copy link
Author

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants