JSONRPCKit icon indicating copy to clipboard operation
JSONRPCKit copied to clipboard

Support for JSONDecoder

Open ollitapa opened this issue 7 years ago • 0 comments

Now that Swift 4 has quite nice JSONDecoder functionality, could we support that using passing instances of Data or Decoder instead of the JSON Dictionary?

Currently the Request gets Any ( [String: Any] ) passed to

func response(from resultObject: Any) throws -> Response 

which in turn needs to be encoded to Data using

let resultData = try JSONSerialization.data(withJSONObject: resultObject, options: [])
let decoder = JSONDecoder()

return try decoder.decode(Response.self, from: resultData)

Could we skip this by passing around Data or Decoder?

like

func response(from resultObject: Data) throws -> Response 

or

func response(from decoder: Decoder) throws -> Response 

Or is this something that limits the generic use of the framework?

ollitapa avatar Apr 03 '18 08:04 ollitapa