When i'm using automatic PojoCodec with Enterprise class that extends from Person class and specilyzes it getDocuments to return a subtype i got that error:
org.bson.codecs.pojo - Cannot use 'Enterprise' with the PojoCodec.org.bson.codecs.pojo - Cannot use 'Enterprise' with the PojoCodec.org.bson.codecs.configuration.CodecConfigurationException: Property 'documents' in Enterprise, has differing data types: TypeData{type=LegalEntityDocuments} and TypeData{type=Documents} at org.bson.codecs.pojo.PojoBuilderHelper.getOrCreateMethodPropertyMetadata(PojoBuilderHelper.java:161) at org.bson.codecs.pojo.PojoBuilderHelper.configureClassModelBuilder(PojoBuilderHelper.java:73) at org.bson.codecs.pojo.ClassModelBuilder.<init>(ClassModelBuilder.java:59) at org.bson.codecs.pojo.ClassModel.builder(ClassModel.java:63) 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 eprecise.libs.arch.persistence.async.kmongo.db.cache.CustomPojoCodecProvider.get(CustomPojoCodecProvider.kt:27) at org.bson.codecs.configuration.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:43) at org.bson.codecs.configuration.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:55) at org.bson.codecs.configuration.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:37) at com.mongodb.internal.operation.Operations.createFindOperation(Operations.java:140) at com.mongodb.internal.operation.Operations.find(Operations.java:129) at com.mongodb.internal.operation.AsyncOperations.find(AsyncOperations.java:84) at com.mongodb.async.client.FindIterableImpl.createFindOperation(FindIterableImpl.java:228) at com.mongodb.async.client.FindIterableImpl.asAsyncReadOperation(FindIterableImpl.java:224) at com.mongodb.async.client.MongoIterableImpl.batchCursor(MongoIterableImpl.java:161) at com.mongodb.async.client.MongoIterableImpl.forEach(MongoIterableImpl.java:77) at eprecise.libs.arch.persistence.async.kmongo.MongoExtensionsKt$toChannel$2.doResume(MongoExtensions.kt:36)
Investigating the problem, i've reached this line at org.bson.codecs.pojo.PojoBuilderHelper:
private static <T, S> PropertyMetadata<T> getOrCreateMethodPropertyMetadata(final String propertyName, final String declaringClassName, final Map<String, PropertyMetadata<?>> propertyNameMap, final TypeData<T> typeData, final Map<String, TypeParameterMap> propertyTypeParameterMap, final TypeData<S> parentClassTypeData, final List<String> genericTypeNames, final Type genericType) { PropertyMetadata<T> propertyMetadata = getOrCreatePropertyMetadata(propertyName, declaringClassName, propertyNameMap, typeData); if (!propertyMetadata.getTypeData().getType().isAssignableFrom(typeData.getType())) { throw new CodecConfigurationException(format("Property '%s' in %s, has differing data types: %s and %s", propertyName, declaringClassName, propertyMetadata.getTypeData(), typeData)); } cachePropertyTypeData(propertyMetadata, propertyTypeParameterMap, parentClassTypeData, genericTypeNames, genericType); return propertyMetadata; }
This seems a bug to me.
In fact, what I want is a mode to parametrize or extends the PojoCodecProvider to not scan methods, and only scan fields.
- is related to
-
JAVA-3097 Create Convention that customises which properties are set
- Backlog