Resolution error solution after gson Obfuscation

Source: Internet
Author: User

Let's take a look at the following ideas:

Solve the problem that JSON cannot be parsed after gson Obfuscation

1. Do not confuse classes in the Google gson jar package

2. All attribute names in the object class implementing java. Io. serializable cannot be confused.

3. for serialization and deserialization, writeobject (); readobject (); writereplace (); readresolve (); cannot be confused.

Therefore, add

-Keep class com. Google .**{*;}

-Keepclassmembers class * implements java. Io. serializable {
Static final long serialversionuid;
Private Static final java. Io. objectstreamfield [] serialpersistentfields;
Private void writeobject (Java. Io. objectoutputstream );
Private void readobject (Java. Io. objectinputstream );
Java. Lang. Object writereplace ();
Java. Lang. Object readresolve ();
}

# ------------- Begin: proguard configuration for gson ----------
# Gson uses generic type information stored in a class file when working with fields. proguard
# Removes such information by default, so configure it to keep all of it.
-Keepattributes Signature
# Gson specific classes
-Keep class sun. Misc. Unsafe {*;}
#-Keep class com. Google. gson. Stream .**{*;}
# Application classes that will be serialized/deserialized over gson
-Keep class com. Google. gson. Examples. Android. model .**{*;}
# ------------- End: proguard configuration for gson ----------



The above code can be directly pasted in.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.