RestTemplate, Jackson and proguard

I am trying to get the application to work 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 query execution ApiUrlResponseData.getLinks()returns null.

This is how I try 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?

+4
source share
1 answer

Parameters are -keepclasseswithmembernamesquite exotic: it stores the names of classes (and their fields and methods) if the classes have all the specified fields and methods. This is mainly useful for preserving JNI classes and methods.

You can save annotated fields and methods:

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

, , .

:

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

, .

+6

Source: https://habr.com/ru/post/1543383/


All Articles