Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jackson fails to deserialize JsonSubTypes when re-running continuous tests #20973

Closed
pschmidt88 opened this issue Oct 25, 2021 · 1 comment · Fixed by #20998
Closed

Jackson fails to deserialize JsonSubTypes when re-running continuous tests #20973

pschmidt88 opened this issue Oct 25, 2021 · 1 comment · Fixed by #20998
Labels
area/jackson Issues related to Jackson (JSON library) area/kotlin kind/bug Something isn't working
Milestone

Comments

@pschmidt88
Copy link

pschmidt88 commented Oct 25, 2021

Describe the bug

I am playing around with Kotlin and Event Sourcing and for that I save different Events in a MongoDB collection.

The event document looks something like this

{
    "_id" : ObjectId("6176613d55215e20e614cf1f"),
    "aggregateId" : UUID("107791f8-8884-45ce-afca-ee648f745f30"),
    "event" : {
        "@class" : "org.acme.event_sourcing.TestEvent",
        "someProperty" : "foo"
    }
}

where TestEvent will be one of the many events in the application. The outer object holds meta information and the event property holds event specific data including the event class name.
To deserialize that I use a custom Codec where I just let jackson take care of deserializing the Mongo Document (by using the JsonTypeInfo feature)

class EventCodec(
    private val documentCodec: Codec<Document> = MongoClientSettings.getDefaultCodecRegistry().get(Document::class.java)
) : Codec<Event> {
    // .. rest of the class omitted ...

    override fun decode(reader: BsonReader?, decoderContext: DecoderContext?): Event {
        val document = documentCodec.decode(reader, decoderContext)
        return objectMapper.readValue(document.toJson())
    }
}

The event class is annoated with JsonTypeInfo and every event inherits this class

@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class")
abstract class Event

This works well in production and on first test runs, but when re-running the continuous tests (with gradle quarkusTest and pressing r after all tests ran) it fails with a jackson deserialization error saying that TestEvent is not a subtype of Event

java.util.concurrent.CompletionException: com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Could not resolve type id 'org.acme.event_sourcing.TestEvent' as a subtype of `org.acme.event_sourcing.Event`: Not a subtype
 at [Source: (String)"{"@class": "org.acme.event_sourcing.TestEvent", "someProperty": "foo"}"; line: 1, column: 12]

Expected behavior

Re-running continuous tests should not fail with a InvalidTypeIdException

Actual behavior

Tests failing with InvalidTypeIdException.

The weird thing is: If I make the test fail on purpose by throwing a random exception in the test code, and then removing that exception, all tests are passing again.
Until re-run 😅

How to Reproduce?

I created a small reproducer here: https://github.com/pschmidt88/quarkus-reproduce-jackson-subtype-error

  1. run continuous tests (I use gradle): ./gradlew quarkusTest
  2. all tests are passing
  3. re-run tests by typing r in the console
  4. related tests failing

Output of uname -a or ver

Linux rookian-XPS-13-9300 5.13.0-20-generic #20-Ubuntu SMP Fri Oct 15 14:21:35 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version "17.0.1" 2021-10-19 OpenJDK Runtime Environment GraalVM CE 21.3.0 (build 17.0.1+12-jvmci-21.3-b05) OpenJDK 64-Bit Server VM GraalVM CE 21.3.0 (build 17.0.1+12-jvmci-21.3-b05, mixed mode, sharing)

GraalVM version (if different from Java)

21.3.0 with java 17 (but same issue with java 11)

Quarkus version or git rev

2.3.0-Final

Build tool (ie. output of mvnw --version or gradlew --version)

gradle 7.2

Additional information

kotlin version used: 1.5.21

Just my first idea (but I'm not really familiar with the framework code so don't take it to serious): Could that be a test runner related issue? As far as I know quarkus runs things in different threads and class loaders - maybe jackson does not support that in some way?

@pschmidt88 pschmidt88 added the kind/bug Something isn't working label Oct 25, 2021
@quarkus-bot
Copy link

quarkus-bot bot commented Oct 25, 2021

/cc @evanchooly, @geoand, @gsmet

@quarkus-bot quarkus-bot bot added area/jackson Issues related to Jackson (JSON library) area/kotlin labels Oct 25, 2021
stuartwdouglas added a commit to stuartwdouglas/quarkus that referenced this issue Oct 26, 2021
NIO async IO uses a custom thread pool, this allows us to update the
TCCL in dev mode.

Fixes quarkusio#20973
@quarkus-bot quarkus-bot bot added this to the 2.5 - main milestone Oct 26, 2021
@gsmet gsmet modified the milestones: 2.5 - main, 2.4.1.Final Nov 2, 2021
gsmet pushed a commit to gsmet/quarkus that referenced this issue Nov 2, 2021
NIO async IO uses a custom thread pool, this allows us to update the
TCCL in dev mode.

Fixes quarkusio#20973

(cherry picked from commit 6c708fe)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/jackson Issues related to Jackson (JSON library) area/kotlin kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants