@@ -264,7 +264,7 @@ extension TestNSJSONSerialization {
264
264
XCTAssertEqual ( result ? [ 1 ] as? Int , - 1 )
265
265
XCTAssertEqual ( result ? [ 2 ] as? Double , 1.3 )
266
266
XCTAssertEqual ( result ? [ 3 ] as? Double , - 1.3 )
267
- XCTAssertEqual ( result ? [ 4 ] as? Double , 1000 )
267
+ XCTAssertEqual ( result ? [ 4 ] as? Int , 1000 )
268
268
XCTAssertEqual ( result ? [ 5 ] as? Double , 0.001 )
269
269
}
270
270
} catch {
@@ -598,6 +598,7 @@ extension TestNSJSONSerialization {
598
598
( " test_invalidJsonObjectToStreamBuffer " , test_invalidJsonObjectToStreamBuffer) ,
599
599
( " test_jsonObjectToOutputStreamInsufficeintBuffer " , test_jsonObjectToOutputStreamInsufficeintBuffer) ,
600
600
( " test_booleanJSONObject " , test_booleanJSONObject) ,
601
+ ( " test_serializeDecimalNumberJSONObject " , test_serializeDecimalNumberJSONObject) ,
601
602
]
602
603
}
603
604
@@ -941,6 +942,21 @@ extension TestNSJSONSerialization {
941
942
XCTAssertTrue ( JSONSerialization . isValidJSONObject ( [ true ] ) )
942
943
}
943
944
945
+ func test_serializeDecimalNumberJSONObject( ) {
946
+ let decimalArray = " [12.1,10.0,0.0,0.0001,20] "
947
+ do {
948
+ let data = decimalArray. data ( using: String . Encoding. utf8)
949
+ let result = try JSONSerialization . jsonObject ( with: data!, options: [ ] ) as? [ Any ]
950
+ XCTAssertEqual ( result ? [ 0 ] as! Double , 12.1 )
951
+ XCTAssertEqual ( result ? [ 1 ] as! Int , 10 )
952
+ XCTAssertEqual ( result ? [ 2 ] as! Int , 0 )
953
+ XCTAssertEqual ( result ? [ 3 ] as! Double , 0.0001 )
954
+ XCTAssertEqual ( result ? [ 4 ] as! Int , 20 )
955
+ } catch {
956
+ XCTFail ( " Failed during serialization " )
957
+ }
958
+ }
959
+
944
960
private func createTestFile( _ path: String , _contents: Data ) -> String ? {
945
961
let tempDir = NSTemporaryDirectory ( ) + " TestFoundation_Playground_ " + NSUUID( ) . uuidString + " / "
946
962
do {
0 commit comments