-
Notifications
You must be signed in to change notification settings - Fork 4.3k
[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
base: main
Are you sure you want to change the base?
Conversation
This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation. |
@Marcono1234 Modified the Exception as per suggestion |
* 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
fromJson
Thanks! I think it would be good to adjust all the other For some of them it would then list But note that I am not a direct member of this project, so this still needs approval from a project member. So feel free to wait with further changes until further feedback from a project member. |
I agree with @Marcono1234 that we should make this documentation change everywhere it applies. I would go further and say that we should also remove all unchecked exceptions from |
…eption
Purpose
Closes #2816
Description
As mentioned in #2816 , If com.google.gson.Gson.fromJson(String, Class) throws JsonSyntaxException but in case any one imeplements custom JsonDeserializer then it by default throws JsonParseException.
For any com.google.gson.Gson.fromJson(String, Class) calls , its normal to catch JsonSyntaxException, But in case use of JsonDeserializer, this exception will not be caught.
Ideally fromJson and JsonDeserializer interface should throw same exceptions.
Updating exception type in Gson#fromJson to JsonParseException
Checklist
This is automatically checked by
mvn verify
, but can also be checked on its own usingmvn spotless:check
.Style violations can be fixed using
mvn spotless:apply
; this can be done in a separate commit to verify that it did not cause undesired changes.null
@since $next-version$
(
$next-version$
is a special placeholder which is automatically replaced during release)TestCase
)mvn clean verify javadoc:jar
passes without errors