Skip to content

Commit cbbe3ef

Browse files
Use PostgresNIO's default JSON coders (vapor#195)
* Use postgres-nio's `_defaultJSONEncoder` and `_defaultJSONDecoder` global variables as the default values for the JSON coders in `PostgresDataEncoder` and `PostgresDataDecoder` * Deprecate the previous "jsonDecoder" variable of PostgresDataDecoder and rename it to "json" * Fix spacing slightly in PostgresDataDecoder * Fix spacing in PostgresDataDecoder
1 parent 806a513 commit cbbe3ef

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import class Foundation.JSONDecoder
2+
3+
extension PostgresDataDecoder {
4+
@available(*, deprecated, renamed: "json")
5+
public var jsonDecoder: JSONDecoder {
6+
return self.json as! JSONDecoder
7+
}
8+
}

Sources/PostgresKit/PostgresDataDecoder.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import Foundation
2+
import protocol PostgresNIO.PostgresJSONDecoder
3+
import var PostgresNIO._defaultJSONDecoder
24

35
public final class PostgresDataDecoder {
4-
public let jsonDecoder: JSONDecoder
6+
public let json: PostgresNIO.PostgresJSONDecoder
57

6-
public init(json: JSONDecoder = JSONDecoder()) {
7-
self.jsonDecoder = json
8+
public init(json: PostgresNIO.PostgresJSONDecoder = PostgresNIO._defaultJSONDecoder) {
9+
self.json = json
810
}
911

1012
public func decode<T>(_ type: T.Type, from data: PostgresData) throws -> T
@@ -19,7 +21,7 @@ public final class PostgresDataDecoder {
1921
}
2022
return value as! T
2123
} else {
22-
return try T.init(from: _Decoder(data: data, json: self.jsonDecoder))
24+
return try T.init(from: _Decoder(data: data, json: self.json))
2325
}
2426
}
2527

@@ -47,9 +49,9 @@ public final class PostgresDataDecoder {
4749
}
4850

4951
let data: PostgresData
50-
let json: JSONDecoder
52+
let json: PostgresJSONDecoder
5153

52-
init(data: PostgresData, json: JSONDecoder) {
54+
init(data: PostgresData, json: PostgresJSONDecoder) {
5355
self.data = data
5456
self.json = json
5557
}
@@ -93,7 +95,7 @@ public final class PostgresDataDecoder {
9395
var currentIndex: Int = 0
9496

9597
let data: [PostgresData]
96-
let json: JSONDecoder
98+
let json: PostgresJSONDecoder
9799
var codingPath: [CodingKey] {
98100
[]
99101
}
@@ -128,7 +130,7 @@ public final class PostgresDataDecoder {
128130

129131
struct _ValueDecoder: SingleValueDecodingContainer {
130132
let data: PostgresData
131-
let json: JSONDecoder
133+
let json: PostgresJSONDecoder
132134
var codingPath: [CodingKey] {
133135
[]
134136
}

Sources/PostgresKit/PostgresDataEncoder.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import Foundation
2+
import protocol PostgresNIO.PostgresJSONEncoder
3+
import var PostgresNIO._defaultJSONEncoder
24

35
public final class PostgresDataEncoder {
4-
public let json: JSONEncoder
6+
public let json: PostgresJSONEncoder
57

6-
public init(json: JSONEncoder = JSONEncoder()) {
8+
public init(json: PostgresJSONEncoder = PostgresNIO._defaultJSONEncoder) {
79
self.json = json
810
}
911

0 commit comments

Comments
 (0)