'How to store custom java objects with ArrayLists in Firebase realtime database

I am trying to store custom java objects in Firebase. These objects have ArrayLists and other object references inside them such as Location. When I try to write these object to the database AndroidStudio gives two errors:

  1. CustomClassMapper.convertToPlainJavaTypes
  2. CustomClassMapper.serialize.

I have read that these issues are due to Firebase only supporting java objects that have default constructors, public getters and implements Serializible.

But also (not sure) the object itself should not reference anything other than supported datattypes of Firebase which are String, Long Double, Boolean, Map<String, Object>, List<Object>.

However in my project my objects has to have ArrayList<Location> references. Any help would be much appreciated.



Solution 1:[1]

Figured it out. I had an object which is called Route. It also had a List which holds Stop objects. When a stop is added to a route, a reference of the Route was also added to Stop to show that, that specific Stop exists in this Route. However, for some reason adding Route(this) reference to Stop and adding Stop to Route(this) crashes the app. I figure it is due to Database holding a copy of the object itself and not a reference which if allowed would result in infinite objects.

Solution: check if you have cross references between your objects.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ali Tunahan I??k