@Override
  public RestLiResponseData<GetResponseEnvelope> buildRestLiResponseData(Request request,
                                                        RoutingResult routingResult,
                                                        Object result,
                                                        Map<String, String> headers,
                                                        List<HttpCookie> cookies)
  {
    final RecordTemplate record;
    final HttpStatus status;
    if (result instanceof GetResult)
    {
      final GetResult<?> getResult = (GetResult<?>) result;
      record = getResult.getValue();
      status = getResult.getStatus();
    }
    else
    {
      record = (RecordTemplate) result;
      status = HttpStatus.S_200_OK;
    }
    final ResourceContext resourceContext = routingResult.getContext();
    DataMap rawData = record.data();
    RecordDataSchema schema = record.schema();
    if (resourceContext.isFillInDefaultsRequested())
    {
      rawData = (DataMap) ResponseUtils.fillInDataDefault(schema, rawData);
    }

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

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

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

    return new RestLiResponseDataImpl<>(new GetResponseEnvelope(status, new AnyRecord(data)), headers, cookies);
  }
@Test
  public void testProjectionInBuildRestliResponseData()
  {
    MaskTree maskTree = new MaskTree();
    maskTree.addOperation(new PathSpec("fruitsField"), MaskOperation.POSITIVE_MASK_OP);

    ServerResourceContext mockContext = getMockResourceContext(maskTree, ProjectionMode.AUTOMATIC);
    RoutingResult routingResult = new RoutingResult(mockContext, getMockResourceMethodDescriptor());

    Foo value = new Foo().setStringField("value").setFruitsField(Fruits.APPLE);

    GetResponseBuilder responseBuilder = new GetResponseBuilder();
    RestLiResponseData<GetResponseEnvelope>
        responseData = responseBuilder.buildRestLiResponseData(null, routingResult, value,
                                                                              Collections.emptyMap(),
                                                                              Collections.emptyList());
    RecordTemplate record = responseData.getResponseEnvelope().getRecord();
    Assert.assertEquals(record.data().size(), 1);
    Assert.assertEquals(record.data().get("fruitsField"), Fruits.APPLE.toString());

    EasyMock.verify(mockContext);
  }