@@ -468,7 +468,7 @@ extension TestNSJSONSerialization {
468468 XCTAssertEqual ( result ? [ 1 ] as? Int , - 1 )
469469 XCTAssertEqual ( result ? [ 2 ] as? Double , 1.3 )
470470 XCTAssertEqual ( result ? [ 3 ] as? Double , - 1.3 )
471- XCTAssertEqual ( result ? [ 4 ] as? Double , 1000 )
471+ XCTAssertEqual ( result ? [ 4 ] as? Int , 1000 )
472472 XCTAssertEqual ( result ? [ 5 ] as? Double , 0.001 )
473473 }
474474 } catch {
@@ -871,6 +871,7 @@ extension TestNSJSONSerialization {
871871 ( " test_jsonObjectToOutputStreamInsufficientBuffer " , test_jsonObjectToOutputStreamInsufficientBuffer) ,
872872 ( " test_booleanJSONObject " , test_booleanJSONObject) ,
873873 ( " test_serialize_dictionaryWithDecimal " , test_serialize_dictionaryWithDecimal) ,
874+ ( " test_serializeDecimalNumberJSONObject " , test_serializeDecimalNumberJSONObject) ,
874875 ]
875876 }
876877
@@ -1214,6 +1215,22 @@ extension TestNSJSONSerialization {
12141215 XCTAssertTrue ( JSONSerialization . isValidJSONObject ( [ true ] ) )
12151216 }
12161217
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+
12171234 fileprivate func createTestFile( _ path: String , _contents: Data ) -> String ? {
12181235 let tempDir = NSTemporaryDirectory ( ) + " TestFoundation_Playground_ " + NSUUID( ) . uuidString + " / "
12191236 do {
0 commit comments