Fix null check bug in mapToJson method #26
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes the failing tests in
JsonMapConverterTestby correcting a logical error in themapToJsonmethod.Problem
The
mapToJsonmethod had an inverted null check condition on line 38:if (map != null)- throws exception when map is NOT nullif (map == null)- throws exception when map IS nullThis bug caused the method to throw an
IllegalArgumentExceptionfor valid (non-null) map inputs, while allowing null inputs to proceed, which is the opposite of the intended behavior.Changes
mapToJsonmethod fromif (map != null)toif (map == null)IllegalArgumentExceptionas expected by the testsmapToPrettyJsonmethod which already had the correct null checkTest Coverage
This fix resolves the following failing tests:
testMapToJson_NullInput- Now correctly throws exception for null inputtestMapToJson_SimpleMap- Now works correctly with valid map inputtestMapToJson_NestedMap- Now works correctly with nested mapstestMapToJson_EmptyMap- Now works correctly with empty mapstestRoundTrip_JsonToMapToJson- Now completes the round-trip conversion successfullyFixes #25