sven-lange-last commented on a change in pull request #4624: Combines active 
ack and slot release when both are available.
URL: https://github.com/apache/openwhisk/pull/4624#discussion_r325238811
 
 

 ##########
 File path: 
common/scala/src/main/scala/org/apache/openwhisk/core/connector/Message.scala
 ##########
 @@ -112,49 +119,51 @@ object CompletionMessage extends DefaultJsonProtocol {
 case class ResultMessage(override val transid: TransactionId, response: 
Either[ActivationId, WhiskActivation])
     extends AcknowledegmentMessage(transid) {
 
-  override def toString = {
-    response.fold(l => l, r => r.activationId).asString
-  }
+  override def toJson: JsValue = ResultMessage.serdes.write(this)
+  override def toString = response.fold(identity, _.activationId).asString
 }
 
-object ResultMessage extends DefaultJsonProtocol {
-  implicit def eitherResponse =
-    new JsonFormat[Either[ActivationId, WhiskActivation]] {
-      def write(either: Either[ActivationId, WhiskActivation]) = either match {
-        case Right(a) => a.toJson
-        case Left(b)  => b.toJson
-      }
+object ActivationMessage extends DefaultJsonProtocol {
+  def parse(msg: String) = Try(serdes.read(msg.parseJson))
 
-      def read(value: JsValue) = value match {
-        // per the ActivationId's serializer, it is guaranteed to be a String 
even if it only consists of digits
-        case _: JsString => Left(value.convertTo[ActivationId])
-        case _: JsObject => Right(value.convertTo[WhiskActivation])
-        case _           => deserializationError("could not read 
ResultMessage")
-      }
-    }
+  private implicit val fqnSerdes = FullyQualifiedEntityName.serdes
+  implicit val serdes = jsonFormat11(ActivationMessage.apply)
+}
 
 Review comment:
   Yes, I'm talking about the companion objects. My concern was that developers 
may miss to update the JSON (de-)serialization of case classes if case classes 
and their companion objects are at different locations of the source file.
   
   If the compiler would notice mismatches, I have no problem with what you did.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to