Skip to content

Commit

Permalink
Add JsonEncoder.DateEncodingStrategy support to control over date s…
Browse files Browse the repository at this point in the history
…erialization in `Encodable` body frames!
  • Loading branch information
Romixery committed Jul 20, 2020
1 parent 9c354e0 commit 8158ec1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion SwiftStomp.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'SwiftStomp'
s.version = '1.0.2'
s.version = '1.0.3'
s.summary = 'An elegant Stomp client for iOS.'
s.description = <<-DESC
SwiftStomp is and elegant, light-weight and easy-to-use STOMP (Simple Text Oriented Messaging Protocol) client for iOS.
Expand Down
8 changes: 4 additions & 4 deletions SwiftStomp/Classes/SwiftStomp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ public extension SwiftStomp{
self.sendFrame(frame: StompFrame(name: .send, headers: headers, dataBody: body))
}

func send <T : Encodable> (body : T, to : String, receiptId : String? = nil, headers : [String : String]? = nil){
func send <T : Encodable> (body : T, to : String, receiptId : String? = nil, headers : [String : String]? = nil, jsonDateEncodingStrategy : JSONEncoder.DateEncodingStrategy = .iso8601){
let headers = prepareHeadersForSend(to: to, receiptId: receiptId, headers: headers)

self.sendFrame(frame: StompFrame(name: .send, headers: headers, encodableBody: body))
self.sendFrame(frame: StompFrame(name: .send, headers: headers, encodableBody: body, jsonDateEncodingStrategy: jsonDateEncodingStrategy))
}

func ack(messageId : String, transaction : String? = nil){
Expand Down Expand Up @@ -539,11 +539,11 @@ fileprivate class StompFrame<T : RawRepresentable> where T.RawValue == String{
self.headers = headers
}

convenience init <X : Encodable>(name : T, headers : [String : String] = [:], encodableBody : X){
convenience init <X : Encodable>(name : T, headers : [String : String] = [:], encodableBody : X, jsonDateEncodingStrategy : JSONEncoder.DateEncodingStrategy = .iso8601){
self.init(name: name, headers: headers)

let jsonEncoder = JSONEncoder()
jsonEncoder.dateEncodingStrategy = .iso8601
jsonEncoder.dateEncodingStrategy = jsonDateEncodingStrategy

if let jsonData = try? jsonEncoder.encode(encodableBody){
self.body = String(data: jsonData, encoding: .utf8)
Expand Down

0 comments on commit 8158ec1

Please sign in to comment.