Skip to content

Instantly share code, notes, and snippets.

@ganadist
Created March 22, 2019 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ganadist/de6176eef9e3011c53656b29dc559669 to your computer and use it in GitHub Desktop.
Save ganadist/de6176eef9e3011c53656b29dc559669 to your computer and use it in GitHub Desktop.
package com.google.gson.functional;
import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
import junit.framework.TestCase;
public class EnumWithObfuscatedTest extends TestCase {
private Gson gson;
@Override
protected void setUp() throws Exception {
super.setUp();
gson = new Gson();
}
public enum Gender {
@SerializedName("MAIL")
MALE,
@SerializedName("FEMAIL")
FEMALE
}
public void testEnumClassWithObfuscated() {
assertEquals(Gender.MALE, gson.fromJson("\"MAIL\"", Gender.class));
assertEquals("\"MAIL\"", gson.toJson(Gender.MALE, Gender.class));
}
}
+ <plugin>
+ <groupId>com.github.wvengen</groupId>
+ <artifactId>proguard-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>process-test-classes</phase>
+ <goals><goal>proguard</goal></goals>
+ </execution>
+ </executions>
+ <configuration>
+ <injar>test-classes</injar>
+ <outjar>test-classes</outjar>
+ <inFilter>com/google/gson/functional/EnumWithObfuscatedTest$Gender</inFilter>
+ <!-- options from Android Gradle Plugins -->
+ <options>
+ <option>-optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*</option >
+ <option>-optimizationpasses 1</option>
+ <option>-allowaccessmodification</option>
+ <option>-keepattributes *Annotation*,Signature,InnerClasses,EnclosingMethod</option>
+ <option>-keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); }</opt ion>
+ </options>
+ <libs>
+ <lib>${java.home}/lib/rt.jar</lib>
+ </libs>
+ </configuration>
+ </plugin>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment