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
Response serialization for TRON 2.0.0 has undergone significant changes, and is influencing experience with TRON.framework in a lot of ways. In this issue we wanted to highlight our goals and current ideas for response serialization.
Previously, ResponseParseable protocol looked like this:
This approach allowed us to put ResponseParseable generic restriction on APIRequest, and gather information about how a model needs to be parsed, directly from a model type. However, it has major flows. First of, you can't create factory parser, that creates subclasses from a model. Second, you can't create protocol, that has several models conforming to it, and parse response to several model types. And third, you are forced to use a constructor, which is problematic for example for CoreData objects, that are not created using a constructor, but instead a created using a static method.
Now, in TRON 2.0.0-beta.2, we are trying a different approach, here's how response serialization protocol looks now:
We are using generic typealiases to define ResponseParser closure like this:
publictypealiasResponseParser=(Data)throws->Model
This way you can directly set your own kind of parser and tweak it in any way. To maintain some form of backwards compatibility, we are adding convenience method for SwiftyJSON subspec users, that prefill response and errorParser with SwiftyJSONDecodable parsers like so:
This is, of course, a huge change, and we want to involve community to discuss better approaches. We are releasing this form of response serialization in TRON 2.0.0-beta.2 for all of you to try it out and will be improving it towards 2.0.0 release.
The text was updated successfully, but these errors were encountered:
This allows us to do several things. First, we are able to use all request information to serialize response, not only data, that was received. Second, we are now constraining our generic Model and ErrorModel types to fit into those two protocols:
Response serialization for TRON 2.0.0 has undergone significant changes, and is influencing experience with TRON.framework in a lot of ways. In this issue we wanted to highlight our goals and current ideas for response serialization.
Previously,
ResponseParseable
protocol looked like this:This approach allowed us to put
ResponseParseable
generic restriction onAPIRequest
, and gather information about how a model needs to be parsed, directly from a model type. However, it has major flows. First of, you can't create factory parser, that creates subclasses from a model. Second, you can't create protocol, that has several models conforming to it, and parse response to several model types. And third, you are forced to use a constructor, which is problematic for example for CoreData objects, that are not created using a constructor, but instead a created using a static method.Now, in TRON 2.0.0-beta.2, we are trying a different approach, here's how response serialization protocol looks now:
And we are adding mandatory response serialization properties to each TRON request method, for example:
We are using generic typealiases to define
ResponseParser
closure like this:This way you can directly set your own kind of parser and tweak it in any way. To maintain some form of backwards compatibility, we are adding convenience method for SwiftyJSON subspec users, that prefill response and errorParser with SwiftyJSONDecodable parsers like so:
This is, of course, a huge change, and we want to involve community to discuss better approaches. We are releasing this form of response serialization in TRON 2.0.0-beta.2 for all of you to try it out and will be improving it towards 2.0.0 release.
The text was updated successfully, but these errors were encountered: