0

I'm trying to use Firebase Android with some simple POJO but I'm getting some exceptions even with the following sample code

final Firebase fb = getFirebaseAccess();
final Subscription subscription = new Subscription(url, System.currentTimeMillis());
Firebase subscriptionRef = fb.child("subscriptions").push();
subscriptionRef.setValue(subscription); // exception thrown here

// Subscription.java

 public class Subscription {

        private String url;
        private long subscribedAt;

        public Subscription() {
        }

        public Subscription(String url, long subscribedAt) {
            this.url = url;
            this.subscribedAt = subscribedAt;
        }

        public String getUrl() {
            return this.url;
        }

        public void setUrl(String url) {
            this.url = url;
        }

        public long getSubscribedAt() {
            return this.subscribedAt;
        }

        public void setSubscribedAt(long subscribedAt) {
            this.subscribedAt = subscribedAt;
        }
    }

The following exception is thrown:

Failed to parse to snapshot com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class com.mypackage.Subscription and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) ) No serializer found for class com.myPackage.Subscription and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) )

I don't understand what's failing because I kept the public default constructor and every variable has its own public getter...

Any idea ?

BTW if I replace the POJO with a String field or a map of attributes it works fine

Edit: I'm using Proguard with minify enabled. I have the following instructions:

# Firebase 2.0
# keep POJOs
-keepnames class com.myPackage.** { *; }
-keep class com.firebase.** { *; }
-keep class org.apache.** { *; }
-keepnames class com.fasterxml.jackson.** { *; }
-keepnames class javax.servlet.** { *; }
-keepnames class org.ietf.jgss.** { *; }
-dontwarn org.w3c.dom.**
-dontwarn org.joda.time.**
-dontwarn org.shaded.apache.**
-dontwarn org.ietf.jgss.**
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
user1026605
  • 1,633
  • 4
  • 22
  • 58

1 Answers1

0

Looks like Jackson related files are being deleted via Proguard, try with the following Proguard Configuration:

    # Proguard configuration for Jackson 2.x (fasterxml package instead of codehaus package)

        -keep class com.fasterxml.jackson.databind.ObjectMapper {
            public <methods>;
            protected <methods>;
        }
        -keep class com.fasterxml.jackson.databind.ObjectWriter {
            public ** writeValueAsString(**);
        }

        # Basic ProGuard rules for Firebase Android SDK 2.0.0+

        -keep class com.firebase.** { *; }
        -keep class org.apache.** { *; }
        -keepnames class com.fasterxml.jackson.** { *; }
        -keepnames class javax.servlet.** { *; }
        -keepnames class org.ietf.jgss.** { *; }
        -dontwarn org.apache.**
        -dontwarn org.w3c.dom.**

# Facebook

-keep class com.facebook.** {*;}
-keepattributes Signature

# Firebase UI

-dontwarn com.firebase.ui.auth.twitter.**
Shajeel Afzal
  • 5,913
  • 6
  • 43
  • 70