When I insert a List into mongodb, there is a problem:
Exception in thread \"main\" java.lang.IllegalArgumentException: can\'t serialize class mongodb.Person
You can achieve this by using following code:
import com.google.gson.annotations.Expose;
import com.mongodb.ReflectionDBObject;
class PersonList extends ReflectionDBObject {
// person property
@Expose public java.util.List person;
}
Now in your mongodb code, you can serialise a Person list as follows
....
PersonList personList = new PersonList();
personList.person = new ArrayList<>();
// add persons to the list
....
....
record.put("personsList", personList);
....
// rest of your code