JSON deserialized DateTime can generate different hashcode from that of DateTime constructed through newInstanceGMT()
Last updated 2018-05-05 ·Reference W-4522765 ·Reported By 2 users
A DataTime object which is deserialized from a JSON string and a DateTime object which is constructed from the DataTime static method could generate different hashcode even though the equality test is evaluated to TRUE.
On a fresh org:
1. Change the locale setting of the current user to "English (United Kingdom)".
2. Run the following apex code in an anonymous block:
DateTime dt1 = DateTime.newInstanceGMT(2017, 11, 29, 0, 0, 0);
DateTime dt2 = (DateTime) JSON.deserialize(JSON.serialize(dt1), DateTime.class);
You'll see it fails with an AssertException in the assertEquals test at line#4 even though the equality test at line#3 passes.
EXCEPTION: System.AssertException: Assertion Failed: Expected: 85616109, Actual: 85616059
STACKTRACE: AnonymousBlock: line 4, column 1
LINE: 4 COLUMN: 1
Explicitly convert Datetime object to string and then back to Datetime.
Is it Fixed?
Any unreleased services, features, statuses, or dates referenced in this or other public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make their purchase decisions based upon features that are currently available.