diff --git a/CodableFirebase/Encoder.swift b/CodableFirebase/Encoder.swift index bf31554..5a2096b 100644 --- a/CodableFirebase/Encoder.swift +++ b/CodableFirebase/Encoder.swift @@ -383,6 +383,8 @@ extension _FirebaseEncoder { return try self.box((value as! Data)) } else if T.self == URL.self || T.self == NSURL.self { return self.box((value as! URL).absoluteString) + } else if T.self == Decimal.self || T.self == NSDecimalNumber.self { + return (value as! NSDecimalNumber) } else if options.skipFirestoreTypes && (value is FirestoreEncodable) { guard let value = value as? NSObject else { throw DocumentReferenceError.typeIsNotNSObject diff --git a/CodableFirebaseTests/TestCodableFirestore.swift b/CodableFirebaseTests/TestCodableFirestore.swift index 236f0ed..c564318 100644 --- a/CodableFirebaseTests/TestCodableFirestore.swift +++ b/CodableFirebaseTests/TestCodableFirestore.swift @@ -109,6 +109,11 @@ class TestCodableFirestore: XCTestCase { _testRoundTrip(of: TopLevelWrapper(date), expected: ["value": date]) } + func testDecimalValue() { + let value = Decimal(2) + _testRoundTrip(of: TopLevelWrapper(value), expected: ["value": value]) + } + // MARK: - GeoPoint & Document Reference func testEncodingGeoPoint() { let point = GeoPoint(latitude: 2, longitude: 2)