Custom object mapper for handling inheritance

Hi guys,
I saw this open issue and can see that it relates to a case we are trying to solve. We are using inheritance on our java objects - abstract class with a bunch of subclasses that we wish to send through an @EndPoint and we would like to differentiate between these on the client side, but are missing type information.
https://github.com/vaadin/hilla/issues/438

We have been testing Jacksons json type annotations but:
From https://vaadin.com/docs/v22/fusion/advanced/type-conversion, I am not sure how we can customize the object mapper. I do not seem to have access to com.vaadin.connect.VaadinConnectController. I am using Vaadin v22.

Have you guys solved similar cases?

Hi,
You can create your own ObjectMapper instance and qualify it with @Qualifier(EndpointController.VAADIN_ENDPOINT_MAPPER_BEAN_QUALIFIER). Then the customization of that mapper is up to you.
But, since #438 is not implemented yet, Hilla won’t be able to map the specialized types and will always return the supertype (AbstractEvent in the issue example).
The trivial workaround is to expose a discriminator property in your bean.

Thanks for your suggestion. We tried with:

@JsonTypeInfo( use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") public class MyObject { ... }

which will include the class name as a type property in the json, but the generated typescript class definition does not include the type property. So,
(obj as MyObject).type
is unknown.

Is is possible to tell the java → ts converter that there is a type property that needs to be included?