Added comprehensive test coverage for safe type casting:
Exception cases (should throw JSONException, not ClassCastException):
- Malformed XML causing type mismatch in toJSONArray()
- Type mismatch in toJSONObject()
Valid cases (should continue to work):
- Valid XML to JSONArray conversion
- Valid XML to JSONObject conversion
These tests verify the fix for issue #1034 where ClassCastException
was thrown when parse() returned unexpected types.
Extracted hex and decimal parsing logic into separate methods to
address SonarQube complexity warning:
- parseHexEntity(): handles ઼ format
- parseDecimalEntity(): handles { format
This reduces cyclomatic complexity while maintaining identical
functionality and all validation checks.
Add type checking before casting parse() results to JSONArray/JSONObject.
When parse() returns an unexpected type (e.g., String for malformed input),
the code now throws a descriptive JSONException instead of ClassCastException.
This prevents unchecked exceptions from propagating to callers who only
expect JSONException from these methods.
Fixes#1034