FrangSierra/RxFirebase

feature request: more info on cast exceptions

robindijkhof opened this issue · 1 comments

Sometimes i'm getting the following exception:

Fatal Exception: java.lang.Throwable
Can't convert object of type java.lang.Long to type models.f
durdinapps.rxfirebase2.DataSnapshotMapper.getDataSnapshotTypedValue (DataSnapshotMapper.java:47)

Though I understand what this means, I can understand why. This seems completely ramdon. I was wondering id we could get some extra info in the exception. Maybe something like this:

private static <U> U getDataSnapshotTypedValue(DataSnapshot dataSnapshot, Class<U> clazz) {
    U value = null;
    try{
         value = dataSnapshot.getValue(clazz);
    }catc(Exception ex){
        throw Exceptions.propagate(new RxFirebaseDataCastException(
            "unable to cast firebase  data response " + dataSnapshot.toString() + " to " + clazz.getSimpleName()));
    }
    if(value == null){
        throw Exceptions.propagate(new RxFirebaseDataCastException(
            "unable to cast firebase  data response " + dataSnapshot.toString() + " to " + clazz.getSimpleName()));
    }
    
    return value;
}

Hello @robindijkhof ,
this have been already fixed on the new version 1.5.5.

Best regards!