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
Allow Data
as Serialized object even if is not valid json
#150
Conversation
Data
as Serialized object even if is not valid sonData
as Serialized object even if is not valid json
Source/Serializer.swift
Outdated
@@ -45,16 +46,19 @@ public extension Serializable { | |||
} | |||
|
|||
/** | |||
Serialize a `Serializable` object and convert the serialized object to `Data`. Unless it is nil the return value is representing a JSON. Usually you don't need to use this method directly since `Router` will automatically serialize objects when needed. | |||
Serialize a `Serializable` object and convert the serialized object to `Data`. Unless it is nil or the serialized object is `Data`, the return value is representing a JSON. Usually you don't need to use this method directly since `Router` will automatically serialize objects when needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line Length Violation: Line should be 100 characters or less: currently 293 characters (line_length)
*/ | ||
func customSerialized(transformingKeys keyTransformer: KeyTransformer?) -> Any? | ||
} | ||
|
||
public extension Serializable { | ||
/** | ||
Serialize a `Serializable` object. The output, unless nil, is convertible to `Data` / JSON. Usually you don't need to use this method directly since `Router` will automatically serialize objects when needed. | ||
Serialize a `Serializable` object. The output, unless nil, is convertible to `Data` or JSON. Usually you don't need to use this method directly since `Router` will automatically serialize objects when needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line Length Violation: Line should be 100 characters or less: currently 213 characters (line_length)
This enable Kakapo to stub other kind of requests, for example we can create a XMLSerializier that when serialized returns the object as Data, or we can implementer `Serializable` for `UIImage`, a really powerful feature that let us use Kakapo not only for JSON responses but every kind of response. This is a basic change that enable us to do so, some more documentation might be written in future and we might decide to move in a direction where Kakapo is less JSON centric
a6a1a6a
to
0129bfa
Compare
@MP0w in your example: how is the result of |
Also |
Sorry toData is not needed, forget about it. |
I see. Then since the serialization also supports Data now, how about making Data/NSData also I think we really should update README to document this properly before merging, otherwise it's a bit misleading how to use it. |
Also, adding a test which shows this usage together with a Router might be also helpful and self documentary for ourselves in the future. |
Interesting your point regarding being less JSON centric: if we have to support different serializations, we might have to separate into different serialization types and wrap everything into a serialization process that takes all types into account maybe. |
The non-JSON centric thing needs a major revision of documentation, README and the way we advertise Kakapo. That's why I think for the moment we can enable it (which is something I would expect to work) and later tackle it |
"adding a test which shows this usage together with a Router might be also helpful" this is already tested I think, router will accept any Data without caring what it contains, because is the only thing needed to create a response |
Yup, didn't say it was not tested: just that it would be self documentary for us in the future I believe. |
@joanromano I wouldn't make |
I will work on something and see how it goes |
This enable Kakapo to stub other kind of requests, for example we can create a XMLSerialzier that when serialized returns the object as Data, or we can implementer
Serialziable
forUIImage
, a really powerful feature that let us use Kakapo not only for JSON responses but every kind of response.This is a basic change that enable us to do so, some more documentation might be written in future and we might decide to move in a direction where Kakapo is less JSON centric
Example:
Usage: