Title: Difference between Firebase instance and DatabaseReference
Tags: android;firebase;firebase-realtime-database
Question: I'm using firebase as back end for my application. 
First I was using Firebase instance to save object to firbase database which worked perfectly fine but I had to change the implementation to get key from object saved for my further implementation. but after changing implementation it discard some of properties when saving.

Following are the codes and screenshots of both implementations.

Implementation 1.

``` Firebase ref = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_advertisement);
        ref = new Firebase("https://xxxxxxxxxxxx.firebaseio.com/");
    }
    addAdvertisement.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


    Mobile mobile = new Mobile(lclManu, lclMdl);
        MobileAdd mobileAdd = new MobileAdd();

        mobileAdd.setMobile(mobile);
        mobileAdd.setPrice(lclPrice);
        mobileAdd.setdescription(lclDes);
        mobileAdd.setDate(date);


        User publishere = new User();
        Log.d("UUID", mAuth.getCurrentUser().getUid());
        publishere.setUUID(mAuth.getCurrentUser().getUid());

        ref.child("Advertisements").push().setValue(mobileAdd);
        }
```

Implementation 2.

```    DatabaseReference ref = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_new_advertisement);
    ref = FirebaseDatabase.getInstance().getReference();

    addAdvertisement.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {

        Mobile mobile = new Mobile(lclManu, lclMdl);
        MobileAdd mobileAdd = new MobileAdd();

        mobileAdd.setMobile(mobile);
        mobileAdd.setPrice(lclPrice);
        mobileAdd.setdescription(lclDes);
        mobileAdd.setDate(date);

        User publishere = new User();
        mobileAdd.setPublisher(publishere);

        DatabaseReference dbRef = ref.child("Advertisements").push();
        dbRef.setValue(mobileAdd);
    }
    }
    });
```

Following is the screenshot with the implementation's result. 


Highlighted properties are missing in second implementation. Why when I save with ```DatabaseReference``` I'm missing these properties and with ```Firebase``` reference I can save obejects without any issues?


Is there a special scenarios we should use these two methods?
Why should we choose one method over another. 
How can I overcome this issue in the second implementation?


Update.

```public class MobileAdd extends Add {


    private Offer offers;
    private Mobile mobile;
    private User publisher;
    private List<String&gt; imagepaths;

    public MobileAdd() {
    }

    public MobileAdd(String description, double price, Date date) {
        super(description, price, date);
    }


    public MobileAdd(String description, double price, Date date,Offer offers, Mobile mobile, User publisher) {
        super(description, price, date);
        this.offers = offers;
        this.mobile = mobile;
        this.publisher = publisher;
    }

    public Offer getOffers() {
        return offers;
    }

    public void setOffers(Offer offers) {
        this.offers = offers;
    }

    public Mobile getMobile() {
        return mobile;
    }

    public void setMobile(Mobile mobile) {
        this.mobile = mobile;
    }

    public User getPublisher() {
        return publisher;
    }

    public void setPublisher(User publisher) {
        this.publisher = publisher;
    }

    public List<String&gt; getImagepaths() {
        return imagepaths;
    }

    public void setImagepaths(List<String&gt; imagepaths) {
        this.imagepaths = imagepaths;
    }
}
```

Class Add.

```public class Add  {

    private String key;
    private String description;
    private double price;
    private Date date;

    protected Add() {
    }
    public Add(String description, double price, Date date) {
        this.description = description;
        this.price = price;
        this.date = date;
    }

    public String getdescription() {
        return description;
    }

    public void setdescription(String description) {
        this.description = description;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }
}
```

Class Mobile

``` public class Mobile{

    private String manufacturer;
    private String model;

    public Mobile() {
    }

    public Mobile(String manufacturer, String model) {
        this.manufacturer = manufacturer;
        this.model = model;
    }

    protected Mobile(Parcel in) {
        manufacturer = in.readString();
        model = in.readString();
    }
    public String getManufacturer() {
        return manufacturer;
    }

    public void setManufacturer(String manufacturer) {
        this.manufacturer = manufacturer;
    }

    public String getModel() {
        return model;
    }

    public void setModel(String model) {
        this.model = model;
    }

}
```

Comment: Post the code for your `MobileAdd` and `Mobile` classes.  _Implementation1_ uses the  Firebase Legacy SDK, which uses Jackson to serialize/deserialize POJOs.  _Implementation2_ uses the new SDK, which does not use Jackson.  The supported annotations and accepted POJO forms are different between the two SDKs.

Comment: @qbix added classes

Here is the accepted answer: As I mentioned in my comment, Implementation1 uses the Firebase Legacy SDK, which uses Jackson to serialize/deserialize POJOs. Implementation2 uses the new SDK, which does not use Jackson. The supported annotations and accepted POJO forms are different between the two SDKs.

The ```description``` field is not written by Implementation2 because of a capitalization error.  The getter/setter methods should be ```getDescription()``` and ```setDescription()``` with capital 'D'.

Also, ```Date``` is not a simple POJO and will not be serialized by the new SDK.  One option is to use Date.getTime() and store the date as a long.



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2017:00:01/08/17', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<android><firebase><firebase-realtime-database>', 'Title': 'Difference between Firebase instance and DatabaseReference', 'ViewCount': 804, 'id': 41535740, 'user_AboutMe': '', 'user_AccountId': 1387123.0, 'user_DisplayName': 'Thusitha Niroshan', 'user_Reputation': 193.0, 'user_Views': 79.0, 'user_id': 1318893.0}}