     XCTAssertEqual(value, decoded, "Decoded \(T.self) <\(decoded)> not equal to original <\(value)>")
 }
 
-func expectRoundTripEqualityThroughJSON<T : Codable>(for value: T) where T : Equatable {
+func expectRoundTripEqualityThroughJSON<T : Codable>(for value: T,
+                                                     encoder: JSONEncoder = JSONEncoder(),
+                                                     decoder: JSONDecoder = JSONDecoder()) where T : Equatable {
     let encode = { (_ value: T) throws -> Data in
-        return try JSONEncoder().encode(value)
-    }
-
+        return try encoder.encode(value)
+    }
+    
     let decode = { (_ data: Data) throws -> T in
-        return try JSONDecoder().decode(T.self, from: data)
-    }
-
+        return try decoder.decode(T.self, from: data)
+    }
+    
     expectRoundTripEquality(of: value, encode: encode, decode: decode)
 }
 

    // MARK: - CGSize
    lazy var cgsizeValues: [CGSize] = [
        CGSize(),
        CGSize(width: 30, height: 40),
        CGSize(width: -30, height: -40),
        // Disabled due to limit on magnitude in JSON. See SR-5346

    // MARK: - CGRect
    lazy var cgrectValues: [CGRect] = [
        CGRect(),
        CGRect.zero,
        CGRect(origin: CGPoint(x: 10, y: 20), size: CGSize(width: 30, height: 40)),
        CGRect(origin: CGPoint(x: -10, y: -20), size: CGSize(width: -30, height: -40)),
        // Disabled due to limit on magnitude in JSON. See SR-5346
        // CGRect.infinite
    ]
    
    func test_CGRect_JSON() {
        for rect in cgrectValues {
            expectRoundTripEqualityThroughJSON(for: rect)
        }
        
        do {
            let rect = CGRect.null
            let encoder = JSONEncoder()
            let decoder = JSONDecoder()
            let inf = "INF", negInf = "-INF", nan = "NaN"
            encoder.nonConformingFloatEncodingStrategy = .convertToString(positiveInfinity: inf,
                                                                          negativeInfinity: negInf,
                                                                          nan: nan)
            decoder.nonConformingFloatDecodingStrategy = .convertFromString(positiveInfinity: inf,
                                                                            negativeInfinity: negInf,
                                                                            nan: nan)
            expectRoundTripEqualityThroughJSON(for: rect, encoder: encoder, decoder: decoder)
        }
    }

