0

I am using mongoDB in java. I want to save java Bitset object in DB, but while performing table.insert(doc) I am getting IllegalArgumentException.

Error :

java.lang.IllegalArgumentException: can't serialize class java.util.BitSet org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:234)

Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367
Shubhra
  • 515
  • 2
  • 8
  • 16

1 Answers1

0

See this question.

Basically, turn your BitSet into a long or byte array, and save that, converting back when you retrieve it.

Community
  • 1
  • 1
daveb
  • 74,111
  • 6
  • 45
  • 51
  • Current I am doing the same i.e. using Byte array. But is there some way I can directly save Bitset Object and not converting it in any other form. – Shubhra Apr 02 '12 at 11:37
  • No. Which is obvious if you look at the BSON spec. Only BSON native types will be directly converted from their Java counterparts. All other types have to be converted to one of the BSON types at the application level. – Remon van Vliet Apr 02 '12 at 13:21
  • We can use third party library for converting java objects to mongo type. In my case I used [morphia](http://code.google.com/p/morphia/) – Shubhra Apr 13 '12 at 08:46