tristanhimmelman / ObjectMapper

Simple JSON Object mapping written in Swift
MIT License
9.16k stars 1.03k forks source link

ImmutableMappable init fix #1079

Closed itruf closed 4 years ago

itruf commented 5 years ago

I've started research to fix warning mentioned here: https://github.com/tristanhimmelman/ObjectMapper/issues/1043#issuecomment-479406127

If you try to init ImmutableMappable with JSONString - swift shows warning that this method has no calls to throwing functions.

I found that:

It causes crashes in some cases.

For example: let response = try? MyModel(JSONString: jsonString) will crash if MyModel is ImmutableMappable and throws in init method.

I'm not sure but it can be caused by selecting optional init from BaseMappable which not marked with throws.

itruf commented 5 years ago

@tristanhimmelman I'm not pretty sure about library architecture. Hope that you will find some time to check my PR.

itruf commented 4 years ago

@tristanhimmelman it's a critical problem with ImmutableMappable. Please check it out.

itruf commented 4 years ago

@tristanhimmelman I'm really sorry for pushing you but it's the very important PR for the project. I hope that you will take a look at it.

itruf commented 4 years ago

Thank you @tristanhimmelman

murad1981 commented 4 years ago

this update caused many crashes in my app where I init an ImmutableMappable from a json string and from a json dict, both now cause runtime crash.

itruf commented 4 years ago

@murad1981 can you show an example of your model and a JSON string caused crash? I think that it's correct behavior if you init an ImmutableMappable model with an incorrect JSON.