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:
spring-data-mongodb 1.0.0.M3
spring-data-commons-core 1.1.0.M1
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?
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.
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.