Custom Marshaller with header

I am trying to create a custom Response Marshaller as follows

implicit val UploadResultResponse: ToResponseMarshaller[UploadResult] =
    fromStatusCodeAndHeadersAndValue[UploadResult]
      .compose {
        result =>
          val headers: List[HttpHeader] =
            result.versionId.fold(List[HttpHeader]()) {
              vId => RawHeader("version-id", vId) :: Nil
            }
          (OK, headers, result)
      }

The ToEntityMarshaller is in the scope.

What I am trying to achieve here is to have version-id header with every response if present.

My route is extending the trait where implicits are defined, but when I am to use in my route I am getting 404 not found, even though constructing manual HttpResponse in route works fine.

Is this the correct way to achieve this?

Regards,

Syed