Skip to content

JacksonOnAndroid

Tatu Saloranta edited this page May 18, 2018 · 14 revisions

This page contains information on various aspects of usage that are specific to Android platform

ProGuard

While there are no standardized settings for ProGuard usage, users have contributed sample settings that may be of use. We are happy to accept more suggestions.

Here are sample settings by @johnjohndoe:

# Jackson
-keep @com.fasterxml.jackson.annotation.JsonIgnoreProperties class * { *; }
-keep @com.fasterxml.jackson.annotation.JsonCreator class * { *; }
-keep @com.fasterxml.jackson.annotation.JsonValue class * { *; }
-keep class com.fasterxml.** { *; }
-keep class org.codehaus.** { *; }
-keepnames class com.fasterxml.jackson.** { *; }
-keepclassmembers public final enum com.fasterxml.jackson.annotation.JsonAutoDetect$Visibility { 
    public static final com.fasterxml.jackson.annotation.JsonAutoDetect$Visibility *;
}

# General
-keepattributes SourceFile,LineNumberTable,*Annotation*,EnclosingMethod,Signature,Exceptions,InnerClasses

and another from @CCorrado:

# Proguard configuration for Jackson 2.x
-keep class com.fasterxml.jackson.databind.ObjectMapper {
    public <methods>;
    protected <methods>;
}
-keep class com.fasterxml.jackson.databind.ObjectWriter {
    public ** writeValueAsString(**);
}
-keepnames class com.fasterxml.jackson.** { *; }
-dontwarn com.fasterxml.jackson.databind.**

Misc other

To avoid wrong name based infered linkage between getter/setter method and field, it is recommended to disable MapperFeature.INFER_PROPERTY_MUTATORS.