Skip to content

Commit

Permalink
Remove extension for JSONEncoder and JSONDecoder (#257)
Browse files Browse the repository at this point in the history
motivation: we should not publicly extend types we do not own

change: remove extensions which are largely API sugar that is not directly related to Lambda
  • Loading branch information
tomerd committed Apr 15, 2022
1 parent 3c3529b commit d35e827
Showing 1 changed file with 0 additions and 14 deletions.
14 changes: 0 additions & 14 deletions Sources/AWSLambdaRuntime/Lambda+Codable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,3 @@ extension JSONEncoder: LambdaCodableEncoder {
return buffer
}
}

extension JSONEncoder {
/// Convenience method to allow encoding json directly into a `String`. It can be used to encode a payload into an `APIGateway.V2.Response`'s body.
public func encodeAsString<T: Encodable>(_ value: T) throws -> String {
try String(decoding: self.encode(value), as: Unicode.UTF8.self)
}
}

extension JSONDecoder {
/// Convenience method to allow decoding json directly from a `String`. It can be used to decode a payload from an `APIGateway.V2.Request`'s body.
public func decode<T: Decodable>(_ type: T.Type, from string: String) throws -> T {
try self.decode(type, from: Data(string.utf8))
}
}

0 comments on commit d35e827

Please sign in to comment.