I am implementing a firebase example as given in their documentations. I am facing this error:
com.fasterxml.jackson.databind.JsonMappingException: No
Your JSON file is not valid. A free online JSON validator : http://jsonlint.com/
Add a constructor in line of:
public BlogPost(String author,String title) {
this.author=author;
this.title=title;
}
However it is also possible you need to redefine BlogPost
to:
class BLogPost {
public BlogPost() { }
String postId;
List<SomeObject> someObject;
Getters/setters
}
In which SomeObject
is your current BLogPost
class.
I'm guessing your BlogPost
class is an inner class of your activity. In that case Java adds a hidden field to each object that refers to the containing object. And this implicit field is of course not present in your JSON data.
To solve this, you should either keep the BlogPost
class in a separate file (so that it's not an inner class) or mark it as a static class (which removes the implicit field):
public static class BlogPost {
Firebase uses -JRHTHaIs-jNPLXOQivY
as the key to your object
{
author: "gracehop"
title: "Announcing COBOL, a New Programming Language"
}
You have to use this as the key to acces the object. You will have to send the correct request to the api. In this case it will be
https://docs-examples.firebaseio.com/web/saving-data/fireblog/posts/-JRHTHaIs-jNPLXOQivY
If you want to receive an array from Firebase you'll have to store it like this.
posts{
"1":{
author: "gracehop"
title: "Announcing COBOL, a New Programming Language"
},
"2":{
author: "alanisawesome"
title: "The Turing Machine"
}
}
Firebase has no native support for arrays. If you store an array, it really gets stored as an “object” with integers as the key names.
Check out this Firebase blog post for more information