0

In my android app I built an object named "Lesson" (which has only 2 fields of strings).

I have a collection on Firestore that one of its fields is an array of "Lessons"(which called "my lessons").

I want to add another lesson to the array. I tried using :

DocumentReference.update("myLessons", FieldValue.arrayUnion(A_LESSON));

but I always get an exception:

 java.lang.IllegalArgumentException: Invalid data. Unsupported type: com.example.classmate.Models.Lesson

But when I tried to do it with integers and strings it worked (despite the fact that I declared the array as a "Lesson" array).

Is it possible to upload to an array a non-preemptive object? how can I upload an object to an array?

Thanks!

2
  • 1
    Add your code that you have tried and also add the exception log Commented Jan 7, 2020 at 17:19
  • the code is the single line that I wrote above. and that is the exception: java.lang.IllegalArgumentException: Invalid data. Unsupported type: com.example.classmate.Models.Lesson Commented Jan 7, 2020 at 17:25

1 Answer 1

1

This appears to be a limitation of the Firestore SDK. The exception being thrown comes from here. The method is figuring out if it can handle the argument passed to FieldValue.arrayUnion(). You're passing a custom type com.example.classmate.Models.Lesson but since it's not one of the accepted types, it throws IllegalArgumentException.

You should instead pass one of the acceptable types as you see in that method parseScalarValue (for example, null, Integer, Double, String, etc).

If you would like to be able to pass a custom class type, I suggest filing a feature request on GitHub for the Firebase SDK.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.