eclipse-ee4j / eclipse-ee4j/yasson

Serialization of inherited interfaces

Open
#467 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
218
Forks
109
Avg merge
1d 5h
Merged PRs (30d)
9

Description

I have the following class setup

```
interface MyInterfaceA {...}
interface MyInterfaceB extends MyInterfaceA {...}

class Foo implements MyInterfaceA {...}
class Bar implements MyInterfaceB {...}

class MySerializer implements JsonbSerializer {...}
```

If I set up Jsonb using Yasson 2.0.1 as follows:

```
JsonbConfig config = new JsonbConfig().withSerializers(new MySerializer());
Jsonb jb = JsonbBuilder.create(config);

jb.toJson(new Foo()); // Serialized using MySerializer
jb.toJson(new Bar()); // Not serialized using MySerializer
```

Then I would expect instances of both `Foo` and `Bar` to be serialized with my serializer, as both implement `MyInterfaceA`. However, that isn't the case and only `Foo` is correctly serialized using my serializer. `Bar` is serialized by the default serializer (as far as I can tell), not by `MySerializer`.

In previous versions of Yasson (tested in 1.0.7), this worked as I expected. I assume this change is unintentional, and therefore a bug that needs fixing.

If this change intentional, how do I restore the old behavior so that anything implementing `MyInterfaceA` (even by inheritance) is serialized using `MySerializer`?

**System information:**
- OS: Ubuntu 18
- Java Version: OpenJDK 11
- Yasson Version: 2.0.1

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the reported JsonbConfig setup with Foo, Bar, MyInterfaceA, MyInterfaceB, and MySerializer on Yasson 2.0.1, then compare the result with Yasson 1.0.7. Trace how serializer lookup handles inherited interfaces. Done means Bar is serialized with MySerializer, or the supported workaround is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.