Skip to content

Commit e22db2a

Browse files
authored
[Config] Revert adding encoder/decoder params to Codable APIs (#14565)
1 parent a17d81c commit e22db2a

File tree

3 files changed

+3
-62
lines changed

3 files changed

+3
-62
lines changed

FirebaseRemoteConfig/CHANGELOG.md

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
# 11.10.0
2-
- [fixed] Codable APIs now accept optional `FirebaseDataEncoder` and
3-
`FirebaseDataDecoder` parameters, allowing for customization of
4-
encoding/decoding behavior. (#14368)
52
- [fixed] Fix intermittent `RCNConfigRealtime` crash due to incorrect parsing of fragmented JSON. (#14518)
63

74
# 11.9.0

FirebaseRemoteConfig/Swift/Codable.swift

+3-27
Original file line numberDiff line numberDiff line change
@@ -44,46 +44,22 @@ public enum RemoteConfigCodableError: Error {
4444
}
4545

4646
public extension RemoteConfig {
47-
/// Decodes the given type from the respective Remote Config values.
47+
/// Decodes a struct from the respective Remote Config values.
4848
///
4949
/// - Parameter asType: The type to decode to.
50-
/// - Throws: An error if the decoding fails.
51-
/// - Returns: The decoded value; otherwise, an error if one occurred.
5250
func decoded<Value: Decodable>(asType: Value.Type = Value.self) throws -> Value {
53-
try decoded(asType: asType, decoder: FirebaseDataDecoder())
54-
}
55-
56-
/// Decodes the given type from the respective Remote Config values.
57-
/// - Parameters:
58-
/// - asType: The type to decode to.
59-
/// - decoder: The encoder to use to decode the given type.
60-
/// - Throws: An error if the decoding fails.
61-
/// - Returns: The decoded value; otherwise, an error if one occurred.
62-
func decoded<Value: Decodable>(asType: Value.Type = Value.self,
63-
decoder: FirebaseDataDecoder) throws -> Value {
6451
let keys = allKeys(from: RemoteConfigSource.default) + allKeys(from: RemoteConfigSource.remote)
6552
let config = keys.reduce(into: [String: FirebaseRemoteConfigValueDecoderHelper]()) {
6653
$0[$1] = FirebaseRemoteConfigValueDecoderHelper(value: configValue(forKey: $1))
6754
}
68-
return try decoder.decode(Value.self, from: config)
55+
return try FirebaseDataDecoder().decode(Value.self, from: config)
6956
}
7057

7158
/// Sets config defaults from an encodable struct.
7259
///
7360
/// - Parameter value: The object to use to set the defaults.
74-
/// - Throws: An error if the encoding fails.
7561
func setDefaults<Value: Encodable>(from value: Value) throws {
76-
try setDefaults(from: value, encoder: FirebaseDataEncoder())
77-
}
78-
79-
/// Sets config defaults from an encodable struct.
80-
/// - Parameters:
81-
/// - value: The object to use to set the defaults.
82-
/// - encoder: The encoder to use to encode the given object.
83-
/// - Throws: An error if the encoding fails.
84-
func setDefaults<Value: Encodable>(from value: Value,
85-
encoder: FirebaseDataEncoder) throws {
86-
guard let encoded = try encoder.encode(value) as? [String: NSObject] else {
62+
guard let encoded = try FirebaseDataEncoder().encode(value) as? [String: NSObject] else {
8763
throw RemoteConfigCodableError.invalidSetDefaultsInput(
8864
"The setDefaults input: \(value), must be a Struct that encodes to a Dictionary"
8965
)

FirebaseRemoteConfig/Tests/Swift/SwiftAPI/Codable.swift

-32
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// limitations under the License.
1414

1515
import FirebaseRemoteConfig
16-
import FirebaseSharedSwift
1716

1817
import XCTest
1918

@@ -207,35 +206,4 @@ class CodableTests: APITestBase {
207206
XCTAssertEqual(readDefaults.arrayValue, ["foo", "bar", "baz"])
208207
XCTAssertEqual(readDefaults.arrayIntValue, [1, 2, 0, 3])
209208
}
210-
211-
// MARK: - Test using injected encoder/decoder.
212-
213-
func testDateEncodingAndDecodingWithNonDefaultCoders() throws {
214-
// Given
215-
struct DateDefaults: Codable {
216-
let date: Date
217-
}
218-
219-
let defaults = DateDefaults(date: Date())
220-
221-
// When
222-
let encoder = FirebaseDataEncoder()
223-
encoder.dateEncodingStrategy = .iso8601
224-
try config.setDefaults(from: defaults, encoder: encoder)
225-
226-
// - Uses default decoder that won't decode ISO8601 format.
227-
let improperlyDecodedDefaults: DateDefaults = try config.decoded()
228-
XCTAssertNotEqual(improperlyDecodedDefaults.date, defaults.date)
229-
230-
// Then
231-
let decoder = FirebaseDataDecoder()
232-
decoder.dateDecodingStrategy = .iso8601
233-
234-
let decodedDefaults: DateDefaults = try config.decoded(decoder: decoder)
235-
XCTAssert(Calendar.current.isDate(
236-
decodedDefaults.date,
237-
equalTo: defaults.date,
238-
toGranularity: .second
239-
))
240-
}
241209
}

0 commit comments

Comments
 (0)