-1

I am trying to insert into mongo DB and am getting the following error when I try and insert a joda big money object

"can't serialize class org.joda.money.BigMoney"

however according to the java doc BigMoney does implement serializable ( http://www.joda.org/joda-money/apidocs/org/joda/money/BigMoney.html )

Why would this error occur when serializable is implemented?

lbalazscs
  • 17,474
  • 7
  • 42
  • 50
James
  • 1
  • 1
  • Do you know that mongo DB is using the built-in Java serialisation? I'm not familiar with it myself, but I wouldn't be surprised if it's using its own serialisation scheme, which may have different requirements than simply implementing `Serializable`. – Andrzej Doyle Oct 02 '13 at 15:13
  • I never used MongoDB, but i know, that it uses JSON as internal Format. So probably you should write a converter which transforms BigMoney to JSON Format? – Sergiy Medvynskyy Oct 02 '13 at 15:16
  • @SergiyMedvynskyy MongoDB uses BSON as an internal format, not JSON. That's a small but important difference. – Philipp Oct 02 '13 at 15:21

1 Answers1

1

The Java driver can only serialise simple primitive types not complex ones - it's not using Java serialisation.

If you want to use Joda money you'll have to do the conversion yourself from the BigMoney object into one (or likely more) primitive values that the driver understands.

This will get a lot easier in the 3.x version of the driver, but for now those are your options.

Trisha
  • 3,891
  • 1
  • 25
  • 39