Android Firebase 2.4 IllegalStateException using new ref.updateChildren()

后端 未结 2 1325
清酒与你
清酒与你 2020-12-10 08:43

When using Firebase 2.4 ref.updateChildren() with HashMap, other than HashMap (e.g. HashMap)

2条回答
  •  独厮守ぢ
    2020-12-10 09:33

    On your last question:

    Is there a way to pass custom HashMap like HashMap to ref.updateChildren() ?

    The Firebase SDK for Android/Java doesn't support directly passing POJOs (like your User class) into updateChildren().

    But what you can do is convert the POJO into a Map with:

    Map userMap = new ObjectMapper().convertValue(user, Map.class);
    

    Then you can put the map of values into the values that you're passing into updateChildren():

    updates.put("users/"+uid, userMap);
    updates.put("lists/"+uid+"/mine, "value");
    
    ref.updateChildren(updates);
    

提交回复
热议问题