Skip to content

[Issue-2816] - Update exception type in Gson#fromJson to JsonParseException #2829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions gson/src/main/java/com/google/gson/Gson.java
Original file line number Diff line number Diff line change
Expand Up @@ -1098,13 +1098,12 @@
* @param classOfT the class of T
* @return an object of type T from the string. Returns {@code null} if {@code json} is {@code
* null} or if {@code json} is empty.
* @throws JsonSyntaxException if json is not a valid representation for an object of type
* classOfT
* @throws JsonParseException if json is not a valid representation for an object of type classOfT
* @see #fromJson(Reader, Class)
* @see #fromJson(String, TypeToken)
*/
public <T> T fromJson(String json, Class<T> classOfT) throws JsonSyntaxException {
public <T> T fromJson(String json, Class<T> classOfT) throws JsonParseException {

Check notice

Code scanning / CodeQL

Confusing overloading of methods Note

Method Gson.fromJson(..) could be confused with overloaded method
fromJson
, since dispatch depends on static types.
return fromJson(json, TypeToken.get(classOfT));
}

/**
Expand Down