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

Serde only deserializes classes implementing an interface, if the interface has an abstract method. #305

Closed
scameronde opened this issue Nov 2, 2022 · 1 comment · Fixed by #310
Assignees

Comments

@scameronde
Copy link

Expected Behavior

Java/Kotlin classes implementing a common interface should be deserializable. Java records should optionally be deserializable.

Actual Behaviour

We noticed some very unexpected behaviour when switching from jackson to serde-jackson, resulting in a runtime exception thrown by the serde object mapper.

We are receiving command objects from RabbitMQ that have a common interface and are discerned by a type parameter. The patterns is:

@Serdeable
@JsonTypeInfo(
    use = JsonTypeInfo.Id.NAME, property = "type"
)
interface Command {
    @JsonTypeName("one")
    class CommandOne implements Command {
    ... more properties here
    }

    @JsonTypeName("one")
    class CommandTwo implements Command {        
    ... more properties here
    }
}

@RabbitListener
class CommandListener {
    @Queue("command.queue")
    public void receive(Command command) {
    }
}

to deserialize JSON objects of the form

{

    "type": "one",
    ... more properties here
}
{

    "type": "two",
    ... more properties here
}

We have installed a Serde deser for micronaut.rabbitmq which is working.

Now to the fun part: when the interface has an abstract method that is implemented by the classes, everything works fine. When the interface has a default method that is overriden by the classes, deserialization fails. If the interface has no method at all, deserialization fails. If we use records instead of classes, the deserialization fails.

I have linked a small project with a unit test and without any technology overhead, that demonstrates the problem.

Steps To Reproduce

Please see the code in the linked example project (just a unit test plus variants of interface/class pattern).

Environment Information

  • Linux (kernel 5)
  • Micronaut 3.7.3
  • Serde
  • Oracle JDK 17

Example Application

https://github.com/scameronde/micronaut-serde-bugreport

Version

3.7.3

@graemerocher
Copy link
Contributor

Thanks for the great issue report. PR sent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants