Fix for custom hash with keys in different order

Instead of returning val when a custom hash is found,
feed it back into val and let the object sorting take
place if required.

Bug: 46895
Change-Id: I6a9b42facd97fbf49042d3a082121ec93659b9f1