bguerout/jongo

Is Jongo compatible with Jackson 2.8.x

hlassiege opened this issue · 6 comments

Hi,

I just upgraded to Spring Boot 1.5.x and I'm using Jongo 1.3.
Spring Boot 1.5.x upgraded its Jackson dependency to 2.8.x. Officially Jongo is compatible with Jackson 2.7.x.

At first, I thought everything was ok but our tests detected a weird behaviour. I'm not sure it's related to Jongo (I'm pretty sure it's not) but I'm curious if you encountered such a thing.

We have a piece of code who works previously like that :

 private FutureAccount find(ObjectId objectId) {
            return futureAccounts.findOne(objectId).as(FutureAccount.class);
    }

futureAccounts is collection. This collections has only objects of type FutureAccount which inherit from SimpleAccount
(FutureAccount extends SimpleAccount)

This code works fine before the upgrade.

Now, the deserialization complains :

java.lang.IllegalArgumentException: Class com.malt.commons.account.SimpleAccount not subtype of [simple type, class com.malt.model.account.FutureAccount]

	at com.fasterxml.jackson.databind.type.TypeFactory.constructSpecializedType(TypeFactory.java:359)
	at com.fasterxml.jackson.databind.jsontype.impl.StdTypeResolverBuilder.buildTypeDeserializer(StdTypeResolverBuilder.java:128)
	at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory.findTypeDeserializer(BasicDeserializerFactory.java:1372)
	at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:482)
	at com.fasterxml.jackson.databind.ObjectReader._prefetchRootDeserializer(ObjectReader.java:1902)
	at com.fasterxml.jackson.databind.ObjectReader.<init>(ObjectReader.java:185)
	at com.fasterxml.jackson.databind.ObjectMapper._newReader(ObjectMapper.java:652)
	at com.fasterxml.jackson.databind.ObjectMapper.reader(ObjectMapper.java:3472)
	at org.jongo.marshall.jackson.configuration.DefaultReaderCallback.getReader(DefaultReaderCallback.java:24)

It would work if we change the previous code like this :

 private FutureAccount find(ObjectId objectId) {
            return (FutureAccount)futureAccounts.findOne(objectId).as(SimpleAccount.class);
    }

Of course it's more problematic for every methods returning an iterable.

Did you encounter this behaviour before ?

Hello,

AFAIK Jongo is compatible with Jackson 2.8.
You can find more informations here : #319

What is the exact version you are using ?

Can you test with the work in progress version of Jongo (1.4) ?

<dependencies>
  <dependency>
    <groupId>org.jongo</groupId>
    <artifactId>jongo</artifactId>
    <version>jongo-1.4-early-20171013-1609</version>
  </dependency>
</dependencies>
...
<repositories>
    <repository>
       <id>cloudbees-jongo-early-release</id>
        <url>http://repository-jongo.forge.cloudbees.com/release</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

ok I'll test it next week I think. Thanks

Currently I resolved this behaviour modification by changing this line kind of statement :

accounts.findOne(objectId).as(FutureAccount.class)

by

(FutureAccount)accounts.findOne(objectId).as(SimpleAccount.class)

Ths change is centralized in the repository so it's ok for me.

Hello 1.3.1 and 1.4.0 have been released.

1.3.1: Jackson fixAcces(true) and Jackson update to 2.7.9
1.4.0: Jackson and bson4jackson updated to 2.9.x and enhancement of Jongo classes extensibility

You can find more informations here: https://github.com/bguerout/jongo/releases