You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In our project, we have been using Immutables Criteria with a MongoDB backend for some time now. Recently, we tried to use Immutables Criteria for a model that uses Jackson's @JsonSubTypes for inheritance. We found that this use case is not fully supported yet.
We were able to make it work, but not without patching some of the Immutables Criteria code. And the patches we had to make are not ideal.
With this issue, I hope to
either point the way to better support for models that use Jackson's `@JsonSubTypes',
or learn how to store and retrieve polymorphic models in a better supported way, but still using Jackson.
To demonstrate the problems we face, I created the following commit 4cdc52c.
I added a simple polymorphic model and a test that tries to insert this model into a MongoDB and fetch again.
The test succeeds against an in-memory database. However, it fails when run against a real MongoDB instance with the following error message:
Caused by: java.lang.ClassCastException: class com.fasterxml.jackson.core.util.JsonParserSequence cannot be cast to class org.immutables.criteria.mongo.bson4jackson.Wrapper (com.fasterxml.jackson.core.util.JsonParserSequence and org.immutables.criteria.mongo.bson4jackson.Wrapper are in unnamed module of loader 'app')
at org.immutables.criteria.mongo.bson4jackson.JacksonCodecs$1.deserialize(JacksonCodecs.java:101)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:129)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:310)
To run the test against a real local MongoDB instance, set the system property -Dmongo=mongodb://localhost as described in the MongoExtension.
The exception that occurs is due to the false assumption in the JacksonCodecs that the JsonParser can be cast into a Wrapper<BsonReader>. This assumption is false as soon as @JsonSubTypes is used, because Jackson wraps the BsonParser with a JsonParserSequence. As a result, the JsonParser can no longer be cast into a Wrapper<BsonReader>.
The text was updated successfully, but these errors were encountered:
Thank you for reporting this! I cannot promise to look into this soon. I would encourage to create a PR as it seems like the cause of the issue and the fix is known
In our project, we have been using Immutables Criteria with a MongoDB backend for some time now. Recently, we tried to use Immutables Criteria for a model that uses Jackson's
@JsonSubTypes
for inheritance. We found that this use case is not fully supported yet.We were able to make it work, but not without patching some of the Immutables Criteria code. And the patches we had to make are not ideal.
With this issue, I hope to
To demonstrate the problems we face, I created the following commit 4cdc52c.
I added a simple polymorphic model and a test that tries to insert this model into a MongoDB and fetch again.
Here is the model:
And here is the test:
The test succeeds against an in-memory database. However, it fails when run against a real MongoDB instance with the following error message:
To run the test against a real local MongoDB instance, set the system property
-Dmongo=mongodb://localhost
as described in theMongoExtension
.The exception that occurs is due to the false assumption in the
JacksonCodecs
that theJsonParser
can be cast into aWrapper<BsonReader>
. This assumption is false as soon as@JsonSubTypes
is used, because Jackson wraps theBsonParser
with aJsonParserSequence
. As a result, theJsonParser
can no longer be cast into aWrapper<BsonReader>
.The text was updated successfully, but these errors were encountered: