Remove accidental invisible characters from Troubleshooting Guide (#2395)

Accidentally contained U+200C (Zero Width Non-Joiner) followed by U+200B (Zero Width Space)
This commit is contained in:
Marcono1234 2023-05-24 23:41:26 +02:00 committed by GitHub
parent ed8ca46aa8
commit 4c65a82871
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 1 deletions

View File

@ -277,7 +277,7 @@ Gson prevents multiple fields with the same name because during deserialization
**Solution:** First check if you really need to serialize or deserialize a `Class`. Often it is possible to use string aliases and then map them to the known `Class`; you could write a custom [`TypeAdapter`](https://javadoc.io/doc/com.google.code.gson/gson/latest/com.google.gson/com/google/gson/TypeAdapter.html) to do this. If the `Class` values are not known in advance, try to introduce a common base class or interface for all these classes and then verify that the deserialized class is a subclass. For example assuming the base class is called `MyBaseClass`, your custom `TypeAdapter` should load the class like this:
```java
Class.forName(jsonString, false, getClass().getClassLoader()).asSubclass(MyBaseClass.class)
Class.forName(jsonString, false, getClass().getClassLoader()).asSubclass(MyBaseClass.class)
```
This will not initialize arbitrary classes, and it will throw a `ClassCastException` if the loaded class is not the same as or a subclass of `MyBaseClass`.