vaadin / hilla

Build better business applications, faster. No more juggling REST endpoints or deciphering GraphQL queries. Hilla seamlessly connects Spring Boot and React to accelerate application development.
https://hilla.dev
Apache License 2.0
911 stars 57 forks source link

Use JsonSubType union type in method parameters and return type #1457

Open Artur- opened 1 year ago

Artur- commented 1 year ago

Describe your motivation

If you have

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY)
@JsonSubTypes({ @JsonSubTypes.Type(value = AddEvent.class, name = "add"),
        @JsonSubTypes.Type(value = UpdateEvent.class, name = "update") })
public interface BaseEvent { public int baseValue; }
public class AddEvent implements BaseEvent { private String addValue;}
public class UpdateEvent implements BaseEvent { private String updateValue;}

then you get

interface BaseEvent {
    baseValue: number;
}

interface UpdateEvent extends BaseEvent {
    updateValue: string;
    "@type": "update";
}

interface AddEvent extends BaseEvent {
    addValue: string;
    "@type": "add";
}

which is expected but then you have

   public void foo(BaseEvent bar) {}

you get

async function foo(bar: BaseEvent)

Describe the solution you'd like

The parameter type should not be BaseEvent but instead BaseEventUnion. The same for the return type

Describe alternatives you've considered

No response

Additional context

No response

tarekoraby commented 11 months ago

@cromoteca, addressing this issue was needed to enable external filters in AutoGrid. Right?