Skip to content

Commit

Permalink
Don't extend JSONEncodable when using Vapor.
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0c committed Jan 4, 2022
1 parent e55c757 commit ebd7d01
Showing 1 changed file with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,18 @@ extension Date: JSONEncodable {
func encodeToJSON() -> Any {
return CodableHelper.dateFormatter.string(from: self)
}
}{{/useVapor}}{{#generateModelAdditionalProperties}}
}

extension JSONEncodable where Self: Encodable {
func encodeToJSON() -> Any {
let encoder = CodableHelper.jsonEncoder
guard let data = try? encoder.encode(self) else {
fatalError("Could not encode to json: \(self)")
}
return data.encodeToJSON()
}
}
{{/useVapor}}{{#generateModelAdditionalProperties}}

extension String: CodingKey {
Expand Down Expand Up @@ -206,13 +217,3 @@ extension Set: RequestDecodable where Element: Content {
extension Set: Content where Element: Content { }

extension AnyCodable: Content {}{{/useVapor}}

extension JSONEncodable where Self: Encodable {
func encodeToJSON() -> Any {
let encoder = CodableHelper.jsonEncoder
guard let data = try? encoder.encode(self) else {
fatalError("Could not encode to json: \(self)")
}
return data.encodeToJSON()
}
}

0 comments on commit ebd7d01

Please sign in to comment.