Results 1 to 10 of 12

Thread: Mongodb/BSON Fails to Serialize when BigInteger used as an ID

Hybrid View

  1. #1

    Default 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
    Attached Files Attached Files

  2. #2
    Join Date
    May 2008
    Location
    Boston, MA
    Posts
    63

    Default

    I believe this is the same issue you are experiencing: https://jira.springsource.org/browse/DATADOC-171

  3. #3

    Default

    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?

  4. #4
    Join Date
    May 2008
    Location
    Boston, MA
    Posts
    63

    Default

    You can grab the fix from here if you can't wait for the next release:

    https://github.com/SpringSource/spri...ede96406ecdfe0

  5. #5

    Default

    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.

  6. #6

    Default

    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?
    Attached Files Attached Files

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •