From 8374ceb034c4d2e07ec029d395a2e9d77fa5010e Mon Sep 17 00:00:00 2001 From: MaicolAntali Date: Mon, 6 Nov 2023 20:23:04 +0100 Subject: [PATCH] Formats `.md` files --- README.md | 6 +++--- Troubleshooting.md | 10 +++++----- UserGuide.md | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 7418a27af7..e0324b7ba7 100644 --- a/README.md +++ b/README.md @@ -47,10 +47,10 @@ Despite supporting older Java versions, Gson also provides a JPMS module descrip These are the optional Java Platform Module System (JPMS) JDK modules which Gson depends on. This only applies when running Java 9 or newer. -- `java.sql` (optional since Gson 2.8.9) +- `java.sql` (optional since Gson 2.8.9) When this module is present, Gson provides default adapters for some SQL date and time classes. -- `jdk.unsupported`, respectively class `sun.misc.Unsafe` (optional) +- `jdk.unsupported`, respectively class `sun.misc.Unsafe` (optional) When this module is present, Gson can use the `Unsafe` class to create instances of classes without no-args constructor. However, care should be taken when relying on this. `Unsafe` is not available in all environments and its usage has some pitfalls, see [`GsonBuilder.disableJdkUnsafe()`](https://javadoc.io/doc/com.google.code.gson/gson/latest/com.google.gson/com/google/gson/GsonBuilder.html#disableJdkUnsafe()). @@ -87,7 +87,7 @@ JDK 11 or newer is required for building, JDK 17 is recommended. ### Contributing -See the [contributing guide](https://github.com/google/.github/blob/master/CONTRIBUTING.md). +See the [contributing guide](https://github.com/google/.github/blob/master/CONTRIBUTING.md). Please perform a quick search to check if there are already existing issues or pull requests related to your contribution. Keep in mind that Gson is in maintenance mode. If you want to add a new feature, please first search for existing GitHub issues, or create a new one to discuss the feature and get feedback. diff --git a/Troubleshooting.md b/Troubleshooting.md index 91fd22110a..8289c93c15 100644 --- a/Troubleshooting.md +++ b/Troubleshooting.md @@ -127,8 +127,8 @@ For example, let's assume you want to deserialize the following JSON data: } ``` -This will fail with an exception similar to this one: `MalformedJsonException: Use JsonReader.setStrictness(Strictness.LENIENT) to accept malformed JSON at line 5 column 4 path $.languages[2]` -The problem here is the trailing comma (`,`) after `"French"`, trailing commas are not allowed by the JSON specification. The location information "line 5 column 4" points to the `]` in the JSON data (with some slight inaccuracies) because Gson expected another value after `,` instead of the closing `]`. The JSONPath `$.languages[2]` in the exception message also points there: `$.` refers to the root object, `languages` refers to its member of that name and `[2]` refers to the (missing) third value in the JSON array value of that member (numbering starts at 0, so it is `[2]` instead of `[3]`). +This will fail with an exception similar to this one: `MalformedJsonException: Use JsonReader.setStrictness(Strictness.LENIENT) to accept malformed JSON at line 5 column 4 path $.languages[2]` +The problem here is the trailing comma (`,`) after `"French"`, trailing commas are not allowed by the JSON specification. The location information "line 5 column 4" points to the `]` in the JSON data (with some slight inaccuracies) because Gson expected another value after `,` instead of the closing `]`. The JSONPath `$.languages[2]` in the exception message also points there: `$.` refers to the root object, `languages` refers to its member of that name and `[2]` refers to the (missing) third value in the JSON array value of that member (numbering starts at 0, so it is `[2]` instead of `[3]`). The proper solution here is to fix the malformed JSON data. To spot syntax errors in the JSON data easily you can open it in an editor with support for JSON, for example Visual Studio Code. It will highlight within the JSON data the error location and show why the JSON data is considered invalid. @@ -178,8 +178,8 @@ And you want to deserialize the following JSON data: } ``` -This will fail with an exception similar to this one: `IllegalStateException: Expected a string but was BEGIN_ARRAY at line 2 column 17 path $.languages` -This means Gson expected a JSON string value but found the beginning of a JSON array (`[`). The location information "line 2 column 17" points to the `[` in the JSON data (with some slight inaccuracies), so does the JSONPath `$.languages` in the exception message. It refers to the `languages` member of the root object (`$.`). +This will fail with an exception similar to this one: `IllegalStateException: Expected a string but was BEGIN_ARRAY at line 2 column 17 path $.languages` +This means Gson expected a JSON string value but found the beginning of a JSON array (`[`). The location information "line 2 column 17" points to the `[` in the JSON data (with some slight inaccuracies), so does the JSONPath `$.languages` in the exception message. It refers to the `languages` member of the root object (`$.`). The solution here is to change in the `WebPage` class the field `String languages` to `List languages`. ## `IllegalStateException`: "Expected ... but was NULL" @@ -287,7 +287,7 @@ This will not initialize arbitrary classes, and it will throw a `ClassCastExcept ## `IllegalStateException`: 'TypeToken must be created with a type argument'
`RuntimeException`: 'Missing type parameter' -**Symptom:** An `IllegalStateException` with the message 'TypeToken must be created with a type argument' is thrown. +**Symptom:** An `IllegalStateException` with the message 'TypeToken must be created with a type argument' is thrown. For older Gson versions a `RuntimeException` with message 'Missing type parameter' is thrown. **Reason:** diff --git a/UserGuide.md b/UserGuide.md index aaf948bc29..aa0b831c84 100644 --- a/UserGuide.md +++ b/UserGuide.md @@ -405,7 +405,7 @@ gson.registerTypeAdapter(MyType.class, new MyDeserializer()); gson.registerTypeAdapter(MyType.class, new MyInstanceCreator()); ``` -`registerTypeAdapter` call checks +`registerTypeAdapter` call checks 1. if the type adapter implements more than one of these interfaces, in that case it registers the adapter for all of them. 2. if the type adapter is for the Object class or JsonElement or any of its subclasses, in that case it throws IllegalArgumentException because overriding the built-in adapters for these types is not supported.