You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When JSON-encoding a dictionary with a Date object, and specifying millisecondsSince1970 for the date encoding strategy, the resulting encoded value for the Date object is a floating point number with some amount of decimal places, instead of an integer representing milliseconds. This doesn't seem correct, I feel like this can cause incompatibility with systems or APIs that don't expect floats for millisecond values (which was the case for my company's Java back-end API).
To reproduce:
let test = ["key": Date()]
let encoder = JSONEncoder()
encoder.dateEncodingStrategy = .millisecondsSince1970
if let result = try? encoder.encode(test) {
if let backToString = String(data: result, encoding: .utf8) {
print("JSON: " + backToString)
}
}
Expected output:
JSON: {"key":1542355551611}
Actual output:
JSON: {"key":1542355551611.2129}
The text was updated successfully, but these errors were encountered:
Additional Detail from JIRA
md5: 26375280f8cb81c834f177bb618146aa
Issue Description:
When JSON-encoding a dictionary with a Date object, and specifying millisecondsSince1970 for the date encoding strategy, the resulting encoded value for the Date object is a floating point number with some amount of decimal places, instead of an integer representing milliseconds. This doesn't seem correct, I feel like this can cause incompatibility with systems or APIs that don't expect floats for millisecond values (which was the case for my company's Java back-end API).
To reproduce:
Expected output:
Actual output:
The text was updated successfully, but these errors were encountered: