Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep constructor if field annotated

Tags:

java

proguard

I have the following class.

public class StatusCategory
{
   @JsonProperty("key")
   private final String m_key = null;

   public String getKey()
   {
      return(m_key);
   }
}

What is the -keep option that will ensure the constructor won't be removed by Proguard?

The following will keep the constructor; however, I don't want to have to specify every single class or package.

-keep class oracle.psr.ndr.jira.api.StatusCategory {<init>;}
like image 625
Nathan Avatar asked Oct 30 '22 00:10

Nathan


1 Answers

Annotate the constructor with @JsonCreator and use -keepclassmembers like so:

-keepclassmembers public class * {
     @com.fasterxml.jackson.annotation.JsonCreator *;
}
like image 82
Wilson Avatar answered Nov 15 '22 05:11

Wilson