diff --git a/akka-javasdk/src/main/scala/akka/javasdk/impl/effect/EffectSupport.scala b/akka-javasdk/src/main/scala/akka/javasdk/impl/effect/EffectSupport.scala index b9fb83cdd..a3bcfadf3 100644 --- a/akka-javasdk/src/main/scala/akka/javasdk/impl/effect/EffectSupport.scala +++ b/akka-javasdk/src/main/scala/akka/javasdk/impl/effect/EffectSupport.scala @@ -16,9 +16,15 @@ import kalix.protocol.component @InternalApi private[impl] object EffectSupport { - def asProtocol(messageReply: MessageReplyImpl[JavaPbAny]): component.Reply = - component.Reply( - Some(ScalaPbAny.fromJavaProto(messageReply.message)), - MetadataImpl.toProtocol(messageReply.metadata)) + def asProtocol(messageReply: MessageReplyImpl[_]): component.Reply = { + val scalaPbAny = + messageReply.message match { + case pb: ScalaPbAny => pb + case pb: JavaPbAny => ScalaPbAny.fromJavaProto(pb) + case other => throw new IllegalStateException(s"Expected PbAny, but was [${other.getClass.getName}]") + } + + component.Reply(Some(scalaPbAny), MetadataImpl.toProtocol(messageReply.metadata)) + } } diff --git a/akka-javasdk/src/main/scala/akka/javasdk/impl/effect/SecondaryEffectImpl.scala b/akka-javasdk/src/main/scala/akka/javasdk/impl/effect/SecondaryEffectImpl.scala index 203299af3..45ab658d7 100644 --- a/akka-javasdk/src/main/scala/akka/javasdk/impl/effect/SecondaryEffectImpl.scala +++ b/akka-javasdk/src/main/scala/akka/javasdk/impl/effect/SecondaryEffectImpl.scala @@ -6,7 +6,6 @@ package akka.javasdk.impl.effect import akka.annotation.InternalApi import akka.javasdk.Metadata -import com.google.protobuf.{ Any => JavaPbAny } import kalix.protocol.component.ClientAction /** @@ -16,7 +15,7 @@ import kalix.protocol.component.ClientAction private[javasdk] sealed trait SecondaryEffectImpl { final def replyToClientAction(commandId: Long): Option[ClientAction] = { this match { - case message: MessageReplyImpl[JavaPbAny] @unchecked => + case message: MessageReplyImpl[_] => Some(ClientAction(ClientAction.Action.Reply(EffectSupport.asProtocol(message)))) case failure: ErrorReplyImpl => Some( diff --git a/akka-javasdk/src/main/scala/akka/javasdk/impl/keyvalueentity/KeyValueEntitiesImpl.scala b/akka-javasdk/src/main/scala/akka/javasdk/impl/keyvalueentity/KeyValueEntitiesImpl.scala index 842ff6a0c..9732c59f1 100644 --- a/akka-javasdk/src/main/scala/akka/javasdk/impl/keyvalueentity/KeyValueEntitiesImpl.scala +++ b/akka-javasdk/src/main/scala/akka/javasdk/impl/keyvalueentity/KeyValueEntitiesImpl.scala @@ -168,8 +168,10 @@ private[impl] final class KeyValueEntitiesImpl( val cmdPayloadPbAny = command.payload.getOrElse( // FIXME smuggling 0 arity method called from component client through here ScalaPbAny.defaultInstance.withTypeUrl(AnySupport.JsonTypeUrlPrefix).withValue(ByteString.empty())) - val cmdBytesPayload = AnySupport.toSpiBytesPayload(cmdPayloadPbAny) - val cmd = service.serializer.fromBytes(cmdBytesPayload) + // FIXME shall we deserialize here or in the router? the router needs the contentType as well. +// val cmdBytesPayload = AnySupport.toSpiBytesPayload(cmdPayloadPbAny) +// val cmd = service.serializer.fromBytes(cmdBytesPayload) + val cmd = cmdPayloadPbAny val context = new CommandContextImpl(thisEntityId, command.name, command.id, metadata, span, tracerFactory) diff --git a/akka-javasdk/src/main/scala/akka/javasdk/impl/view/ViewsImpl.scala b/akka-javasdk/src/main/scala/akka/javasdk/impl/view/ViewsImpl.scala index 3587cb64a..7f6a6473f 100644 --- a/akka-javasdk/src/main/scala/akka/javasdk/impl/view/ViewsImpl.scala +++ b/akka-javasdk/src/main/scala/akka/javasdk/impl/view/ViewsImpl.scala @@ -99,8 +99,10 @@ final class ViewsImpl(_services: Map[String, ViewService[_]], sdkDispatcherName: } val commandName = receiveEvent.commandName - val bytesPayload = AnySupport.toSpiBytesPayload(receiveEvent.getPayload) - val msg = service.serializer.fromBytes(bytesPayload) + // FIXME shall we deserialize here or in the router? the router needs the contentType as well. +// val bytesPayload = AnySupport.toSpiBytesPayload(receiveEvent.getPayload) +// val msg = service.serializer.fromBytes(bytesPayload) + val msg = receiveEvent.getPayload val metadata = MetadataImpl.of(receiveEvent.metadata.map(_.entries.toVector).getOrElse(Nil)) val addedToMDC = metadata.traceId match { case Some(traceId) =>