-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
gson.toJson 抛出 java.lang.AssertionError: java.lang.NoSuchFieldException: ONLINE #2038
Comments
use version: 'com.alibaba:fastjson:1.1.70.android' |
i update gson to 'com.google.code.gson:gson:2.8.9' |
Could you please verify whether you are using ProGuard? In 2.8.8 an issue with enum constant names and ProGuard usage was fixed (#1495). The Most likely obfuscation performed by ProGuard is causing the issues you are seeing. Please either edit your ProGuard config to not obfuscate or shrink your model classes you are using with Gson, or use Gson's Note that I am not a member of this project. |
yes, there have enum constant that using ProGuard, but this model classes in third part jar, so i cannot modify this code. |
It should also be possible to specify ProGuard keep settings for third party libraries, see for example this StackOverflow answer. However, in general you should be careful when using Gson on third party classes or JDK classes. Gson by default gets private fields of classes, even though the author might not have intended them to be used publicly. This could cause your application to break when the author of the library changes the internal implementation and removes or renames those private fields. |
emmm,first the third party library made ProGuard, not my app, so i can do nothing of obfuscation. |
Could you please create a small complete example project which can be used to reproduce this with Gson? (And ideally also showing how it correctly works with Fastjson.) Otherwise it is difficult to find out what is causing this issue. |
i upload a test project on github. address link: GsonTest THX! |
Thank you! It looks like the additional JSON properties, such as |
i see now. its not a normal model classes. |
Gson version
com.google.code.gson:gson:2.8.0
Java / Android version
Android 9+as arctic fox
Used tools
Description
new Gson().toJsont(object); enter crash.
found into this code
why throw new AssertionError(e); , not NoSuchFieldException
Expected behavior
not crash!!!
Actual behavior
crashed !!! even add try-catch(Exception e)
Reproduction steps
Exception stack trace
The text was updated successfully, but these errors were encountered: