Skip to content

Commit 49436f3

Browse files
committed
Fix #561 (second part): improved exception message for unrecognized JSON token
1 parent 51ad218 commit 49436f3

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

release-notes/VERSION-2.x

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ JSON library.
2020
for async parsing
2121
#517: Add `JsonGenerator.writeStartObject(Object, int)` (needed by CBOR, maybe Avro)
2222
#549: Add configurability of "quote character" for JSON factory
23+
#561: Misleading exception for unquoted String parsing
2324
- Rewrite `JsonGenerator.copyCurrentStructure()` to remove recursion)
2425
- Add `missingNode()`, `nullNode()` in `TreeCodec`
2526
- Add `JsonParserDelegate.delegate()` methods

src/main/java/com/fasterxml/jackson/core/base/ParserBase.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -1049,22 +1049,28 @@ protected void _throwUnquotedSpace(int i, String ctxtDesc) throws JsonParseExcep
10491049

10501050
/**
10511051
* @return Description to use as "valid tokens" in an exception message about
1052-
* invalid (unrecognized) token
1052+
* invalid (unrecognized) JSON token: called when parser finds something that
1053+
* looks like unquoted textual token
10531054
*
10541055
* @since 2.10
10551056
*/
10561057
protected String _validJsonTokenList() throws IOException {
1057-
return "('null', 'true', 'false' or NaN)";
1058+
return _validJsonValueList();
10581059
}
10591060

10601061
/**
10611062
* @return Description to use as "valid JSON values" in an exception message about
1062-
* invalid (unrecognized) JSON value
1063+
* invalid (unrecognized) JSON value: called when parser finds something that
1064+
* does not look like a value or separator.
10631065
*
10641066
* @since 2.10
10651067
*/
1068+
@SuppressWarnings("deprecation")
10661069
protected String _validJsonValueList() throws IOException {
1067-
return "(number, String, array, object, 'true', 'false' or 'null')";
1070+
if (isEnabled(Feature.ALLOW_NON_NUMERIC_NUMBERS)) {
1071+
return "(JSON String, Number (or 'NaN'/'INF'/'+INF'), Array, Object or token 'null', 'true' or 'false')";
1072+
}
1073+
return "(JSON String, Number, Array, Object or token 'null', 'true' or 'false')";
10681074
}
10691075

10701076
/*

0 commit comments

Comments
 (0)