Shajeel Afzal Shajeel Afzal - 1 year ago 207
Android Question

com.firebase.client.FirebaseException: Failed to parse node with class class CLASS_NAME android

I am getting following exception while updating an existing value in the Firebase using


com.firebase.client.FirebaseException: Failed to parse node with class class com.shajeelafzal.quicktasks_app.models.HashTagModel
at com.firebase.client.snapshot.NodeUtilities.NodeFromJSON(
at com.firebase.client.snapshot.NodeUtilities.NodeFromJSON(
at com.firebase.client.utilities.Validation.parseAndValidateUpdate(
at com.firebase.client.Firebase.updateChildren(
at com.shajeelafzal.quicktasks_app.fragments.AddEditTaskFragment$4.onDataChange(

My model looks like this:

public class HashTagModel implements Parcelable {

private HashMap<String, Object> timeStampLastUsed;
private String name;
private String createByUserEmail;
private List<String> tasksKeys;

public HashTagModel() {

public HashTagModel(HashMap<String, Object> timeStampLastUsed, String name,
String createByUserEmail, ArrayList<String> tasksKeys) {
this.timeStampLastUsed = timeStampLastUsed; = name;
this.createByUserEmail = createByUserEmail;
this.tasksKeys = tasksKeys;

JSON Object that I want to update looks like this on Firebase:

"hashTags" : {
"USA" : {
"createByUserEmail" : "USER_EMAIL",
"name" : "#USA",
"tasksKeys" : [ "-K6mS36uhKthKf1-1pF1" ],
"timeStampLastUsed" : {
"timestamp" : 1451514461234

And my
method looks like this:

public void onDataChange(DataSnapshot dataSnapshot) {
/** if the hash tag does not exists already then create new one. */
if (dataSnapshot.getValue() == null) {
HashMap<String, Object> timestampJoined = new HashMap<>();
timestampJoined.put(Constants.FIREBASE_PROPERTY_TIMESTAMP, ServerValue.TIMESTAMP);

ArrayList<String> keysList = new ArrayList<String>();

HashTagModel hashTag = new HashTagModel(timestampJoined, "#" + mHashTags.get(finalI),
Utils.decodeEmail(mEncodedEmail), keysList);
} else {

HashTagModel hashtaghModel = dataSnapshot.getValue(HashTagModel.class);


/* HashMap for data to update */
HashMap<String, Object> updateUserTaskData = new HashMap<>();

Utils.updateMapForAllWithValue(null, mHashTags.get(finalI), mEncodedEmail,
updateUserTaskData, "", hashtaghModel, Constants.FIREBASE_LOCATION_USER_HASH_TAGS);

/** update the Hash Tag */
finalHashTagLocation.updateChildren(updateUserTaskData, new Firebase.CompletionListener() {
public void onComplete(FirebaseError firebaseError, Firebase firebase) {
Log.i("", "");


Answer Source

Unlike the setValue() method, updateChildren() does not perform a Java-to-JSON conversion on the value(s) you pass in.

You're passing a HashMap<String, Object> into updateChildren(), which fits the contract of that API. But I'm pretty sure in some of the values you have a Java object (likely a HashTagModel) that is not directly mapped to a JSON type.

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

Map<String, Object> hashtaghMap = new ObjectMapper().convertValue(hashtaghModel, Map.class);

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download