Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-3915

Unable to map Kotlin data class with an annotated field

    • Type: Icon: New Feature New Feature
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 4.1.1
    • Component/s: POJO
    • None

      I'm using the PojoCodecProvider to map to Kotlin data classes. When the fields of those data classes contain annotations (unrelated to MongoDB) then an exception is thrown.

      Stacktrace:

      java.lang.NullPointerException: null
      	at org.bson.codecs.pojo.PojoBuilderHelper.isAssignableClass(PojoBuilderHelper.java:169)
      	at org.bson.codecs.pojo.PojoBuilderHelper.getOrCreateMethodPropertyMetadata(PojoBuilderHelper.java:160)
      	at org.bson.codecs.pojo.PojoBuilderHelper.configureClassModelBuilder(PojoBuilderHelper.java:94)
      	at org.bson.codecs.pojo.ClassModelBuilder.<init>(ClassModelBuilder.java:60)
      	at org.bson.codecs.pojo.ClassModel.builder(ClassModel.java:68)
      	at org.bson.codecs.pojo.PojoCodecProvider.createClassModel(PojoCodecProvider.java:215)
      	at org.bson.codecs.pojo.PojoCodecProvider.getPojoCodec(PojoCodecProvider.java:82)
      	at org.bson.codecs.pojo.PojoCodecProvider.get(PojoCodecProvider.java:72)
      	at org.bson.internal.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:45)
      	at org.bson.internal.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:57)
      	at org.bson.internal.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:39)
      	at com.mongodb.internal.operation.Operations.createFindOperation(Operations.java:131)
      	at com.mongodb.internal.operation.Operations.find(Operations.java:121)
      	at com.mongodb.internal.operation.SyncOperations.find(SyncOperations.java:93)
      	at com.mongodb.client.internal.FindIterableImpl.asReadOperation(FindIterableImpl.java:206)
      	at com.mongodb.client.internal.MongoIterableImpl.execute(MongoIterableImpl.java:135)
      	at com.mongodb.client.internal.MongoIterableImpl.iterator(MongoIterableImpl.java:92)
      	at com.mongodb.client.internal.MongoIterableImpl.iterator(MongoIterableImpl.java:39)
      	
              ....
      	at java.lang.Thread.run(Thread.java:748)
      2020-12-18 09:25:11.341 [nioEventLoopGroup-4-1 @call-handler#4] ERROR Application - Unhandled: GET - /restaurants
      org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class com.fificard.domain.Restaurant.
      	(Coroutine boundary)
      	...
      	at java.lang.Thread.run(Thread.java:748)
      Caused by: org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class com.fificard.domain.Restaurant.
      	at org.bson.internal.CodecCache.getOrThrow(CodecCache.java:57)
      	at org.bson.internal.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:64)
      	at org.bson.internal.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:39)
      	at com.mongodb.internal.operation.Operations.createFindOperation(Operations.java:131)
      	at com.mongodb.internal.operation.Operations.find(Operations.java:121)
      	at com.mongodb.internal.operation.SyncOperations.find(SyncOperations.java:93)
      	at com.mongodb.client.internal.FindIterableImpl.asReadOperation(FindIterableImpl.java:206)
      	
      	... 13 common frames omitted
      

      It seems that it sees the annotation itself as a property to map.
       

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            fiftyfifty@paoapps.com Lammert Westerhoff
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: