Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RestTemplate, Jackson and proguard

I'm trying to get app working after obfuscation. I have two simple classes:

public class ApiUrlResponseData
{

    @JsonProperty( "@links" )
    List<Link> links;

    public List<Link> getLinks()
    {
        return links;
    }
}

public class Link 
{
    @JsonProperty( "url" )
    String url;

    @JsonProperty( "name" )
    String name;

    @JsonProperty( "mobile" )
    Boolean mobile;

    public Link()
    {
    }

    public Link( String url, String name, Boolean mobile )
    {
        this.url = url;
        this.name = name;
        this.mobile = mobile;
    }

    public String getUrl()
    {
        return url;
    }

    public String getName()
    {
        return name;
    }

    public Boolean isMobile()
    {
        return mobile;
    }
}

Unfortunately after obfuscation and request executing ApiUrlResponseData.getLinks() returns null.

Here is how I'm trying to prevent obfuscation for data objects:

 -keepclasseswithmembernames class com.companyname.android.network.data.** {
       public <fields>;
       protected <fields>;
       <fields>;

       @org.codehaus.jackson.annotate.* <fields>;
       @org.codehaus.jackson.annotate.* <init>(...);
    }

What am I missing?

like image 686
Eugen Martynov Avatar asked Mar 20 '23 10:03

Eugen Martynov


1 Answers

The options -keepclasseswithmembernames is pretty exotic: it keeps the names of classes (and of their fields and methods), if the classes have all the specified fields and methods. It is mostly useful for preserving JNI classes and methods.

You could keep the annotated fields and methods:

-keepclassmembers class * {
    @org.codehaus.jackson.annotate.* *;
}

Unfortunately, you then have to make sure all involved fields and methods are annotated.

It may be easier to keep all fields and methods of serialized classes like these:

-keepclassmembers class com.example.ApiUrlResponseData,
                        com.example.Link {
    *;
}

You can use wildcards or also annotations to specify them.

like image 56
Eric Lafortune Avatar answered Mar 23 '23 16:03

Eric Lafortune