How to skip null/empty variables in the firestore collection?

I found an easy way using Gson to serialize object then convert into the map then you can save that object

private Map<String, Object> removeNullValues(User userObject) {
    Gson gson = new GsonBuilder().create();

    Map<String, Object> map = new Gson().fromJson(
            gson.toJson(userObject), new TypeToken<HashMap<String, Object>>() {
            }.getType()
    );

    return map;
}

and then

documentReference
.set( removeNullValues( userObject) )
.addOnSuccessListener {}

If you are using proguard then make sure add this rules

-keepclassmembers enum * { *; }