This patch documents that JSON strings returned by
OpenSRF::Utils::JSON->perl2JSON() should not be expected to have
hash keys sorted in any particular order. It also adjusts a
corresponding test case to consistently pass under Perl 5.18, which
introduces hash order randomization.
Forcing JSON output to be in canonical form is another option, and
easily done by JSON::XS, but would add overhead.
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Bill Erickson <berick@esilibrary.com>
=head2 perl2JSON
Given a Perl object, returns a JSON stringified representation of that
-object.
+object. Callers should not expect that the JSON string has hash keys
+sorted in any particular order.
=cut
#
# perl2JSON
my $jsonstr = OpenSRF::Utils::JSON->perl2JSON($fakeobj);
-is ($jsonstr, '{"__c":"osrfException","__p":{"foo":"bar"}}');
+ok (
+ ($jsonstr eq '{"__c":"osrfException","__p":{"foo":"bar"}}' ||
+ $jsonstr eq '{"__p":{"foo":"bar"},"__c":"osrfException"}'),
+ 'JSON corresponds to Perl object (though hash key order by vary)'
+);
#