DatabaseException: Found two getters or fields with conflicting case sensitivity

前端 未结 3 429
耶瑟儿~
耶瑟儿~ 2020-12-06 07:26

Every time I try to retrieve data from my database, I get

com.google.firebase.database.DatabaseException: Found two getters or fields with conflicting case s         


        
相关标签:
3条回答
  • 2020-12-06 07:34

    I found a different solution to keep my field public String id and at the same time have the method public String getId() which I needed to implement because of an interface: Simply mark the method with @Exclude, e.g.:

    public class Group implements Identifiable<String>
    {
        public String id;
    
        protected Group ()
        {
        }
    
        public Group ( String id )
        {
            this.id = id;
        }
    
        @Exclude
        @Override
        public String getId ()
        {
            return id;
        }
    }
    
    0 讨论(0)
  • 2020-12-06 07:54

    Convert the following fields from public to private

    public int K;
    public double L;
    public int D;
    public int N;
    

    to

    private int K;
    private double L;
    private int D;
    private int N;
    
    0 讨论(0)
  • 2020-12-06 07:57

    The Firebase Database consider these items when serializing/deserializing JSON:

    • public fields
    • JavaBean-like property getters/setters

    Since you have both a public field N and getN()/setN() methods, it considers the two in conflict. While in this case setting N and calling setN() leads to the same result, that may not always be the case. The chance of getting it wrong is too big, which is why the scenario is simply not allowed.

    The error message is a bit of a red herring in this case. We should improve that.

    0 讨论(0)
提交回复
热议问题