You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The internal method JsonReaderInternalAccess.promoteNameToValue(JsonReader) which is used before the key of a Map<K,V> is read causes an incorrect JSON path because after the name has been read as value, the JSON path is not updated.
For example:
StringmalformedJson = "{\"name\":\"value";
try {
newGson().fromJson(malformedJson, newTypeToken<Map<String, String>>() {}.getType());
} catch (JsonSyntaxExceptionexception) {
// Incorrect: Path is missing name// Unterminated string at line 1 column 15 path $.System.out.println(exception.getCause().getMessage());
}
JsonReaderjsonReader = newJsonReader(newStringReader(malformedJson));
jsonReader.beginObject();
jsonReader.nextName();
try {
jsonReader.nextString();
} catch (MalformedJsonExceptionexception) {
// Correct: Path includes name// Unterminated string at line 1 column 15 path $.nameSystem.out.println(exception.getMessage());
}
Activity
Update JSON path after promoteNameToValue consumes a map key.
Update JSON path after promoteNameToValue (#3098)