Skip to content

Commit e1a0dd2

Browse files
authored
Fix for encoding Decimal (#4)
Also make options optional when turning into data
1 parent ed46fda commit e1a0dd2

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

Sources/GeoJSONKit/GeoJSON+Codable.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ extension GeoJSON.GeometryObject: Codable {
7878
try container.encode(triple, forKey: .coordinates)
7979
} else if let quatruple = coordinates as? [[[[Double]]]] {
8080
try container.encode(quatruple, forKey: .coordinates)
81+
} else if let single = coordinates as? [Decimal] {
82+
try container.encode(single, forKey: .coordinates)
83+
} else if let double = coordinates as? [[Decimal]] {
84+
try container.encode(double, forKey: .coordinates)
85+
} else if let triple = coordinates as? [[[Decimal]]] {
86+
try container.encode(triple, forKey: .coordinates)
87+
} else if let quatruple = coordinates as? [[[[Decimal]]]] {
88+
try container.encode(quatruple, forKey: .coordinates)
8189
} else {
8290
throw CodingError.unsupportedCoordinateCount
8391
}

Sources/GeoJSONKit/GeoJSON.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ public struct GeoJSON: Hashable {
465465
}
466466

467467

468-
public func toData(options: JSONSerialization.WritingOptions) throws -> Data {
468+
public func toData(options: JSONSerialization.WritingOptions = []) throws -> Data {
469469
return try JSONSerialization.data(withJSONObject: toJSON(), options: options)
470470
}
471471

0 commit comments

Comments
 (0)