2

This might be a dumb question but I couldn't find any examples on google's firebase site. If I have a key in the firebase database of "First Name" and then I call

FirstNameClass firstName = dataSnapshot.getValue(FirstNameClass.class);

FireNameClass{
    Private String FirstName;
    FirstName(){
    }
    FirstName(String firstName){
        this.FirstName = firstName;
    }
}

It'll return null because it's trying to map to FirstName instead of First Name with a space. Is there a different way to achieve this because all my values have spaces in them just by design and I am willing to do extra work to keep this design if possible.

Torewin
  • 64
  • 1
  • 11

2 Answers2

4

Try using @PropertyName. Your model should look like this:

FireNameClass{

    @PropertyName("First Name")
    public String FirstName;
    ...
}

Note: I haven't tried it. If it doesn't work, I think I know another way to do it and will update this answer

Hope this helps

koceeng
  • 2,169
  • 3
  • 16
  • 37
  • 1
    You are amazing! It works perfectly. Is there other way a cleaner way or just different? – Torewin Mar 25 '17 at 04:10
  • There is another way, by replacing your space with "_" or something and replace it back when you retrieve value from database. But I think above one is much more cleaner. – koceeng Mar 25 '17 at 04:13
0

This got me most of the way there, however I needed to modify where @PropertyName went. Check this answer: https://stackoverflow.com/a/42635329/4151220

Jacob
  • 588
  • 1
  • 4
  • 14