Skip to content

JsonbSerializer order when using inheritance / polymorphism #234

Open
@benneq

Description

@benneq

I'm testing some Jsonb stuff with Quarkus 1.4.1 and quarkus-resteasy-jsonb, and I came across the following inconsistent behavior:

class Foo { ... }
class Bar extends Foo { ... }

class FooSerializer implements JsonbSerializer<Foo> { ... }
class BarSerializer implements JsonbSerializer<Bar> { ... }

class MyJsonbConfigCustomizer implements JsonbConfigCustomizer {
  public void customize(JsonbConfig config) {
    config.withSerializers(new FooSerializer(), new BarSerializer());
  }
}

@Path("/test")
public class TestResource {
  @GET
  public Bar test() { ... }
}

Now when I hit my /test Resource, the response isn't consistent between application restarts. Sometimes FooSerializer is called, and sometimes BarSerializer.

I was hoping that there's some kind of "most precise type" hierarchy, that automatically favors BarSerializer.

Is this intended? Or is this an error in Quarkus' / Resteasy's implementation?

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationInvolves the spec or javadocs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions