Skip to content

Conversation

@marko-kriskovic
Copy link
Owner

Summary

This PR fixes issue #1 by correcting an inverted null check condition in the mapToJson method.

Problem

The mapToJson method in JsonMapConverter.java had an inverted null check on line 40:

if (map != null) {
    throw new IllegalArgumentException("Map cannot be null");
}

This caused the method to:

  • Throw IllegalArgumentException when the map was not null (incorrect)
  • Allow null values to proceed to gson.toJson(map) (incorrect)

Solution

Changed the condition to properly validate null input:

if (map == null) {
    throw new IllegalArgumentException("Map cannot be null");
}

Now the method correctly:

  • Throws IllegalArgumentException when the map is null (correct)
  • Allows valid map objects to be converted to JSON (correct)

Testing

All tests in JsonMapConverterTest should now pass:

  • testMapToJson_SimpleMap
  • testMapToJson_NestedMap
  • testMapToJson_EmptyMap
  • testMapToJson_NullInput
  • testRoundTrip_JsonToMapToJson

Fixes #1

The condition in mapToJson was inverted (checking if map != null instead of map == null),
causing IllegalArgumentException to be thrown when map was not null, and allowing null
values to proceed. This fix corrects the condition to properly validate null input.

Fixes #1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Padaju testovi

2 participants