@Override
  @SuppressWarnings({"unchecked"})
  public RestLiResponseData<PartialUpdateResponseEnvelope> buildRestLiResponseData(Request request,
                                                                                   RoutingResult routingResult,
                                                                                   Object result,
                                                                                   Map<String, String> headers,
                                                                                   List<HttpCookie> cookies)
  {
    UpdateResponse updateResponse = (UpdateResponse) result;

    // Verify that the status in the UpdateResponse is not null. If so, this is a developer error.
    if (updateResponse.getStatus() == null)
    {
      throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR,
          "Unexpected null encountered. HttpStatus is null inside of an UpdateResponse returned by the resource method: "
              + routingResult.getResourceMethod());
    }

    final ResourceContext resourceContext = routingResult.getContext();

    RecordTemplate entityResponse = null;
    // Add patched entity to the response if result is an UpdateEntityResponse and the client is asking for the entity
    if (result instanceof UpdateEntityResponse && resourceContext.isReturnEntityRequested())
    {
      UpdateEntityResponse<?> updateEntityResponse = (UpdateEntityResponse<?>) updateResponse;
      if (updateEntityResponse.hasEntity())
      {
        DataMap entityData = updateEntityResponse.getEntity().data();

        TimingContextUtil.beginTiming(resourceContext.getRawRequestContext(),
            FrameworkTimingKeys.SERVER_RESPONSE_RESTLI_PROJECTION_APPLY.key());

        final DataMap data = RestUtils.projectFields(entityData, resourceContext);

        TimingContextUtil.endTiming(resourceContext.getRawRequestContext(),
            FrameworkTimingKeys.SERVER_RESPONSE_RESTLI_PROJECTION_APPLY.key());

        // Returned entity is to be added to the response envelope
        entityResponse = new EntityResponse<>(data, updateEntityResponse.getEntity().getClass());
      }
      else
      {
        // The entity in the UpdateEntityResponse should not be null. This is a developer error.
        // If trying to return an error response, a RestLiServiceException should be thrown in the resource method.
        throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR,
            "Unexpected null encountered. Entity is null inside of an UpdateEntityResponse returned by the resource method: "
                + routingResult.getResourceMethod());
      }
    }

    return new RestLiResponseDataImpl<>(new PartialUpdateResponseEnvelope(updateResponse.getStatus(), entityResponse), headers, cookies);
  }
@Test(dataProvider = "responseExceptionData")
  public void testBuilderException(UpdateResponse response)
  {
    Map<String, String> headers = ResponseBuilderUtil.getHeaders();
    PartialUpdateResponseBuilder partialUpdateResponseBuilder = new PartialUpdateResponseBuilder();

    RoutingResult routingResult = getMockRoutingResult(true, null);

    try
    {
      partialUpdateResponseBuilder.buildRestLiResponseData(null, routingResult, response, headers, Collections.emptyList());
      Assert.fail("buildRestLiResponseData should have failed because of a null HTTP status or a null entity.");
    }
    catch (RestLiServiceException e)
    {
      Assert.assertTrue(e.getMessage().contains("Unexpected null encountered."));
    }
  }