Java Generic Service Descriptor Elements: Match Error


I’m writing a collection of services that will have certain common responsibilities, such as being auditable (and thus needing the ability to dump their event logs on demand). I tried defining an interface that my service interface could extend containing the method declarations for the audit endpoints, but as every system has its own set of events I made the Event streamed type generic.

This causes errors when Lagom attempts to locate serializers for the generic types.

Caused by: scala.MatchError: Doc (of class sun.reflect.generics.reflectiveObjects.TypeVariableImpl)
	at com.lightbend.lagom.internal.javadsl.api.CallResolver.$anonfun$registeredMessageSerializerFor$1(ServiceCallResolver.scala:46)
	at scala.Option.orElse(Option.scala:289)
	at com.lightbend.lagom.internal.javadsl.api.CallResolver.registeredMessageSerializerFor(ServiceCallResolver.scala:44)
	at com.lightbend.lagom.internal.javadsl.api.CallResolver.messageSerializerFor(ServiceCallResolver.scala:26)
	at com.lightbend.lagom.internal.javadsl.api.CallResolver.resolveMessageSerializer(ServiceCallResolver.scala:17)
	at com.lightbend.lagom.internal.javadsl.api.ServiceReader$.$anonfun$resolveServiceDescriptor$3(ServiceReader.scala:150)

Is this improveable? or should I abandon my attempt to create a common interface for all of the services

I’m not familiar enough with the state of reflection in java 8 to guess if the real type information is readily available. It is present in the interface declaration.

What I’m attempting is approximated by:

interface AuditableService<Doc> {
    ServiceCall<NotUsed, Source<Doc, ?>> getServiceLogs();

interface MyService extends Service, AuditableService<MyEventType> {

    default Descriptor descriptor() {

Thanks for any advice.

1 Like

@SattaiLanfear would you be able to upload an example project that reproduces this to GitHub so we can try it? Thanks!

I created a fairly minimal example project here

The root of why this was sought out for my project was a desire to have several services with a certain set of monitoring and reporting functions in common, even though they had different data collected (so each needed their own response object). Using an interface to enforce it was thought to make code review and ideally some reuse easier.