@@ -468,7 +468,7 @@ extension TestNSJSONSerialization {
468
468
XCTAssertEqual ( result ? [ 1 ] as? Int , - 1 )
469
469
XCTAssertEqual ( result ? [ 2 ] as? Double , 1.3 )
470
470
XCTAssertEqual ( result ? [ 3 ] as? Double , - 1.3 )
471
- XCTAssertEqual ( result ? [ 4 ] as? Double , 1000 )
471
+ XCTAssertEqual ( result ? [ 4 ] as? Int , 1000 )
472
472
XCTAssertEqual ( result ? [ 5 ] as? Double , 0.001 )
473
473
}
474
474
} catch {
@@ -871,6 +871,7 @@ extension TestNSJSONSerialization {
871
871
( " test_jsonObjectToOutputStreamInsufficientBuffer " , test_jsonObjectToOutputStreamInsufficientBuffer) ,
872
872
( " test_booleanJSONObject " , test_booleanJSONObject) ,
873
873
( " test_serialize_dictionaryWithDecimal " , test_serialize_dictionaryWithDecimal) ,
874
+ ( " test_serializeDecimalNumberJSONObject " , test_serializeDecimalNumberJSONObject) ,
874
875
]
875
876
}
876
877
@@ -1214,6 +1215,22 @@ extension TestNSJSONSerialization {
1214
1215
XCTAssertTrue ( JSONSerialization . isValidJSONObject ( [ true ] ) )
1215
1216
}
1216
1217
1218
+ func test_serializeDecimalNumberJSONObject( ) {
1219
+ let decimalArray = " [12.1,10.0,0.0,0.0001,20, \( Int . max) ] "
1220
+ do {
1221
+ let data = decimalArray. data ( using: String . Encoding. utf8)
1222
+ let result = try JSONSerialization . jsonObject ( with: data!, options: [ ] ) as? [ Any ]
1223
+ XCTAssertEqual ( result ? [ 0 ] as! Double , 12.1 )
1224
+ XCTAssertEqual ( result ? [ 1 ] as! Int , 10 )
1225
+ XCTAssertEqual ( result ? [ 2 ] as! Int , 0 )
1226
+ XCTAssertEqual ( result ? [ 3 ] as! Double , 0.0001 )
1227
+ XCTAssertEqual ( result ? [ 4 ] as! Int , 20 )
1228
+ XCTAssertEqual ( result ? [ 5 ] as! Int , Int . max)
1229
+ } catch {
1230
+ XCTFail ( " Failed during serialization " )
1231
+ }
1232
+ }
1233
+
1217
1234
fileprivate func createTestFile( _ path: String , _contents: Data ) -> String ? {
1218
1235
let tempDir = NSTemporaryDirectory ( ) + " TestFoundation_Playground_ " + NSUUID( ) . uuidString + " / "
1219
1236
do {
0 commit comments