File tree Expand file tree Collapse file tree 4 files changed +12
-4
lines changed
Swift/Source/Codable/third_party
third_party/FirestoreEncoder Expand file tree Collapse file tree 4 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -1033,7 +1033,7 @@ extension _FirestoreDecoder {
1033
1033
}
1034
1034
}
1035
1035
1036
- // Decoding an embeded container, this requires expanding the storage stack and
1036
+ // Decoding an embedded container, this requires expanding the storage stack and
1037
1037
// then restore after decoding.
1038
1038
storage. push ( container: value)
1039
1039
let decoded = try T ( from: self )
Original file line number Diff line number Diff line change @@ -35,6 +35,10 @@ extension Firestore {
35
35
/// - Returns: A Map keyed by String representing a document Firestore
36
36
/// API can work with.
37
37
public func encode< T: Encodable > ( _ value: T ) throws -> [ String : Any ] {
38
+ // DocumentReference and FieldValue cannot be encoded directly.
39
+ guard T . self != DocumentReference . self && T . self != FieldValue . self else {
40
+ throw FirestoreEncodingError . encodingIsNotSupported
41
+ }
38
42
guard let topLevel = try _FirestoreEncoder ( ) . box_ ( value) else {
39
43
throw EncodingError . invalidValue ( value,
40
44
EncodingError . Context ( codingPath: [ ] ,
@@ -495,7 +499,7 @@ extension _FirestoreEncoder: SingleValueEncodingContainer {
495
499
}
496
500
497
501
/// Special subclass of `_FirestoreEncoder` used by `superEncoder`.
498
- /// It inherits the codingPath from the referencing `_FirestoreEncoder` but uses it's own
502
+ /// It inherits the codingPath from the referencing `_FirestoreEncoder` but uses its own
499
503
/// storage. The encoded result will be written back to the referencing encoder's storage
500
504
/// when it is `deinit`-ed.
501
505
private class _FirestoreReferencingEncoder : _FirestoreEncoder {
Original file line number Diff line number Diff line change @@ -1033,7 +1033,7 @@ extension _FirestoreDecoder {
1033
1033
}
1034
1034
}
1035
1035
1036
- // Decoding an embeded container, this requires expanding the storage stack and
1036
+ // Decoding an embedded container, this requires expanding the storage stack and
1037
1037
// then restore after decoding.
1038
1038
storage. push ( container: value)
1039
1039
let decoded = try T ( from: self )
Original file line number Diff line number Diff line change @@ -35,6 +35,10 @@ extension Firestore {
35
35
/// - Returns: A Map keyed by String representing a document Firestore
36
36
/// API can work with.
37
37
public func encode< T: Encodable > ( _ value: T ) throws -> [ String : Any ] {
38
+ // DocumentReference and FieldValue cannot be encoded directly.
39
+ guard T . self != DocumentReference . self && T . self != FieldValue . self else {
40
+ throw FirestoreEncodingError . encodingIsNotSupported
41
+ }
38
42
guard let topLevel = try _FirestoreEncoder ( ) . box_ ( value) else {
39
43
throw EncodingError . invalidValue ( value,
40
44
EncodingError . Context ( codingPath: [ ] ,
@@ -495,7 +499,7 @@ extension _FirestoreEncoder: SingleValueEncodingContainer {
495
499
}
496
500
497
501
/// Special subclass of `_FirestoreEncoder` used by `superEncoder`.
498
- /// It inherits the codingPath from the referencing `_FirestoreEncoder` but uses it's own
502
+ /// It inherits the codingPath from the referencing `_FirestoreEncoder` but uses its own
499
503
/// storage. The encoded result will be written back to the referencing encoder's storage
500
504
/// when it is `deinit`-ed.
501
505
private class _FirestoreReferencingEncoder : _FirestoreEncoder {
You can’t perform that action at this time.
0 commit comments