Open loicmathieu opened 7 months ago
can you try:
class Controller<T extends Example> {
@Get(uri = "/")
public T example() {
var example = new ExampleExtended();
example.setProps1("props1");
example.setProps2("props2");
return example;
}
}
Not sure if we should fix this personally, using only the static types to compute serialisers is better for performance.
It didn't work.
Not sure if we should fix this personally, using only the static types to compute serialisers is better for performance.
Well, performance is one thing, and usability is another. I'm really surprised that nobody has this issue before me as it's very common to have a method using subtypes of the declaring return type. This is Java OO basics.
Yes this is the intended behavior as of mn 4. We serialize using the static type now, except for types such as Object or I believe when there's @JsonSubTypes
Expected Behavior
From a controller, when we return a subtype of the declared type, the response should contain the properties of the subtype.
For example with the following controller
The response should be
Actual Behaviour
Starting with Micronaut 4, the response didn't include the properties from the subtype anymore.
The response from the previous example is now
Fun fact, if I use
Object
as a return type it works. It of course works if I useExampleExtended
as a return type but on my real world usage I cannot as I need to return the declared type or a subtype based on some query param.Steps To Reproduce
Here is a reproducer with Micronaut 4.2.1 but we reproduce it also with 4.0.7 which is the version we try to migrate to. controller-polymorphism.zip
Environment Information
OS: Linux *** #14-Ubuntu SMP PREEMPT_DYNAMIC Tue Nov 14 14:59:49 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux Java: OpenJDK Runtime Environment Temurin-17.0.8.1+1 (build 17.0.8.1+1)
Example Application
No response
Version
4.0.7, 4.2.1