Add comprehensive test coverage for JsonParser #4768
  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 adds comprehensive test coverage for the
JsonParserutility class, focusing on error handling, edge cases, and previously untested functionality.Changes
Error Handling Tests (3 tests)
shouldThrowExceptionWhenJsonIsMalformed- ValidatesIllegalStateExceptionis thrown for malformed JSON withfromJson(Class)shouldThrowExceptionWhenJsonIsMalformedWithType- Validates error handling forfromJson(Type)overloadshouldThrowExceptionWhenJsonIsMalformedWithTypeReference- Validates error handling forfromJson(TypeReference)overloadGeneric Collections Support (2 tests)
fromJsonToListWithTypeReference- Tests deserialization of JSON arrays to typedList<Integer>fromJsonToMapWithTypeReference- Tests deserialization of JSON objects to typedMap<String, String>Null Parameter Validation (2 tests)
shouldThrowExceptionWhenValueIsNullInToTypedObject- Ensures null value parameter throwsIllegalArgumentExceptionshouldThrowExceptionWhenTypeIsNullInToTypedObject- Ensures null type parameter throwsIllegalArgumentExceptionPrimitive Type Handling (3 tests)
fromObjectToPrimitiveInt- Tests conversion to primitiveinttypefromObjectToPrimitiveLong- Tests conversion to primitivelongtypefromObjectToPrimitiveBoolean- Tests conversion to primitivebooleantypeEdge Cases (4 tests)
shouldThrowExceptionWhenConversionFails- ValidatesNumberFormatExceptionfor invalid number formatsfromEmptyJsonObject- Tests parsing empty JSON object{}fromEmptyJsonArray- Tests parsing empty JSON array[]toTypedObjectWithNonParsableJsonString- Tests fallback behavior when JSON string parsing failsTesting
All new tests pass and improve overall test coverage for the
JsonParserclass. The tests validate: