jakartaee / jakartaee/jsonb-api
JsonbSerializer order when using inheritance / polymorphism
- Dominant language
- Java
- Stars
- 95
- Forks
- 41
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 35
Description
I'm testing some Jsonb stuff with Quarkus 1.4.1 and quarkus-resteasy-jsonb, and I came across the following inconsistent behavior:
```java
class Foo { ... }
class Bar extends Foo { ... }
class FooSerializer implements JsonbSerializer { ... }
class BarSerializer implements JsonbSerializer { ... }
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?
Contributor guide
Research direction
Start by reproducing the /test response with FooSerializer and BarSerializer registered through MyJsonbConfigCustomizer, across application restarts. Read the JsonbSerializer and JsonbConfigCustomizer usage in the example, then determine whether serializer selection should favor Bar for a returned Bar; done means the behavior is explained and made deterministic or documented as intended.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100