Closed jenschude closed 1 month ago
For implementations of interfaces, the typename should be automatically added. In any case, we recently added the feature to request __typename
on the interface type as well : v6.1.10. Please give that a try for the typename.
Yes this already helps. But it's still an explicit call to be able to deserialize it to one of the subtypes.
When projecting fields of the parent type only it should be sufficient to deserialize to this type as default.
Yes you would need to use the OnImplementationType
to get the subtypes along with the __typename
field.
The code generator supports polymorphic interfaces like the one below:
Using the generator is creates all the necessary types and query/projection classes. But there is one drawback, when only using fields from the interface you still have to do a projection against one of the subtypes, cause the interface doesn't define a default implementation:
.projection(p -> p.value().onMoney().centAmount())
. TheonMoney
method in this case creates a projection query like this:The __typeName field here is important to be able to correctly deserialize the polymorphic type:
Without the call to the
on
-method the __typeName field will not be queried and the deserializer fails withAdding the attribute
defaultImpl
to the BaseMoneys JsonTypeInfo and generating a defaultImpl class sufficient for the interface this would save the necessary call to one of theon
methods in the projection.projection(p -> p.value().centAmount())
cause now the deserializer knows which class to instantiate in case there is no discriminator property available in the response.Generate additionally this class as default implementation of the interface