Jul 13th, 2011, 09:07 AM
Mongodb/BSON Fails to Serialize when BigInteger used as an ID
I instantiated a repository using BigInteger as the ID class:
public interface PersonRepository extends PagingAndSortingRepository<Person, BigInteger>
When I run the test (source and maven pom attached) which attempts to save a Person object to my mongodb, I get the following error:
java.lang.IllegalArgumentException: can't serialize class java.math.BigInteger
at org.bson.BSONEncoder.putNumber(BSONEncoder.java:31 7)
at org.bson.BSONEncoder._putObjectField(BSONEncoder.j ava:168)
at org.bson.BSONEncoder.putObject(BSONEncoder.java:10 5)
at org.bson.BSONEncoder.putObject(BSONEncoder.java:70 )
When I look at BSONEncoder.putNumber() it only supports Integer. Is BigInteger fully supported as an alternative to String?
I am using:
Jul 17th, 2011, 06:23 AM
I believe this is the same issue you are experiencing: https://jira.springsource.org/browse/DATADOC-171
Jul 17th, 2011, 06:44 AM
Thanks for that - I had searched but for BigInteger. I would imagine that the BigInteger problem can be fixed by converting the BigInteger to org.bson.types.ObjectId?
Jul 17th, 2011, 08:47 AM
You can grab the fix from here if you can't wait for the next release:
Jul 17th, 2011, 09:35 AM
Looks like only BigDecimal is fixed in that JIRA. However I will see if I can extend the same principle to BigInteger - since its Id I need tosee if the converters will be applied.
Jul 27th, 2011, 08:19 AM
We tried writing our own custom converter (attached) however it did not work.
The JIRA fixes problems with non-ID fields where MappingMongoConverter.writeInternal() -> DBObject.put() -> ConversionService.convert() on the object which will utilise our converter. However but for ID fields it just does a straight put() on the object. Thus does not invoke the converter.
Is this a bug that needs to be logged in JIRA?
Tags for this Thread