Not called JsonAnySetter method with proguard process

392 views
Skip to first unread message

Jin Yong Choi

unread,
Dec 7, 2013, 9:15:36 AM12/7/13
to jackso...@googlegroups.com

Hi, I am new to Jackson. :)

I have question about Jackson databinding and proguard.

@JsonAnySetter is not working if I use proguard before running it. Of course it's OK without proguard.

The following lines are example to reproduce my problem. 

------------------------------------------------------------------------------------------------------
public static class Item1
{
        @JsonAnySetter
        public void handleUnknown(String key, Object val)
        {
            System.out.println(String.format("unknown : %s - %s", key, val.toString()));
        }

@JsonProperty("uid")
public long uid_ = 0;
}

ObjectMapper m = new ObjectMapper()
m.setVisibilityChecker(getSerializationConfig().getDefaultVisibilityChecker()
                .withFieldVisibility(JsonAutoDetect.Visibility.NONE)
                .withGetterVisibility(JsonAutoDetect.Visibility.NONE)
                .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE)
                .withSetterVisibility(JsonAutoDetect.Visibility.NONE)
                .withCreatorVisibility(JsonAutoDetect.Visibility.NONE));


String j1 = "{\"uid\":5, \"pos\":5, \"kk\":888, \"attr\":5}";
Item1 item = (Item1) m.readValue(Item1.class);
------------------------------------------------------------------------------------------------------

Above program failed with error "com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "kk" (class cca.news.TestJson$Item1), not marked as ignorable"

Next lines are my proguard.cfg file

------------------------------------------------------------------------------------------------------

-dontobfuscate
-dontoptimize

-dontwarn

-keepattributes *Annotation*,EnclosingMethod,Signature
-keepnames class com.fasterxml.jackson.** { *; }
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {
    native <methods>;
}
-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmember class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

-keepclassmembers class * {
    @fully.qualified.package.AnnotationType *;
}


-keep public class cca.news.TestJson.** { *; }

------------------------------------------------------------------------------------------------------

My anysetter handler is working when I turn off proguard.

Is there anybody who have solution?

I need both of proguard and AnySetter handler.


Tatu Saloranta

unread,
Dec 9, 2013, 1:19:55 PM12/9/13
to jackso...@googlegroups.com
I don't know (I don't have experience with ProGuard). Hopefully someone else can suggest something -- it sounds like perhaps @JsonAnySetter annotation was dropped during build process.

Which version of Jackson is this with?

-+ Tatu +-


--
You received this message because you are subscribed to the Google Groups "jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user...@googlegroups.com.
To post to this group, send email to jackso...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages