1

I know how to save a list of String

Now, e.g. I create my own Animal class

But when I try to save list in mongodb, it gives

java.lang.IllegalArgumentException: can't serialize class Project

I do create a new mongo collection Animal, but it is still not working.

mu is too short
  • 426,620
  • 70
  • 833
  • 800
RobinBattle
  • 220
  • 4
  • 14
  • mongo stores json (bson actually) not java objects. You probably need to use the java mongo driver to store the data. – Kevin Mar 04 '12 at 00:52

2 Answers2

1

If Animal class extend ReflectionDBObject then you can insert list of Animals.

Animal extends ReflectionDBObject {

}
Parvin Gasimzade
  • 25,180
  • 8
  • 56
  • 83
1

You might check out Morphia or similar, where you can create object models and save them directly to Mongo.

http://code.google.com/p/morphia/

Eve Freeman
  • 32,467
  • 4
  • 86
  • 101