@Override
  public HttpResponse encode(Supplier<HttpResponse> factory, Response response) {
    int status = response.getStatus() == ErrorCodes.SUCCESS
                 ? HTTP_OK
                 : HTTP_INTERNAL_ERROR;

    byte[] data = json.toJson(getValueToEncode(response)).getBytes(UTF_8);

    HttpResponse httpResponse = factory.get();
    httpResponse.setStatus(status);
    httpResponse.setHeader(CACHE_CONTROL, "no-cache");
    httpResponse.setHeader(EXPIRES, "Thu, 01 Jan 1970 00:00:00 GMT");
    httpResponse.setHeader(CONTENT_LENGTH, String.valueOf(data.length));
    httpResponse.setHeader(CONTENT_TYPE, JSON_UTF_8.toString());
    httpResponse.setContent(data);

    return httpResponse;
  }
@ Override public HttpResponse encode ( Supplier < HttpResponse > factory , Response response ) { int status = response . getStatus ( ) == ErrorCodes . SUCCESS ? HTTP_OK : HTTP_INTERNAL_ERROR ; byte [ ] data = json . toJson ( getValueToEncode ( response ) ) . getBytes ( UTF_8 ) ; HttpResponse httpResponse = factory . get ( ) ; httpResponse . setStatus ( status ) ; httpResponse . setHeader ( CACHE_CONTROL , "no-cache" ) ; httpResponse . setHeader ( EXPIRES , "Thu, 01 Jan 1970 00:00:00 GMT" ) ; httpResponse . setHeader ( CONTENT_LENGTH , String . valueOf ( data . length ) ) ; httpResponse . setHeader ( CONTENT_TYPE , JSON_UTF_8 . toString ( ) ) ; httpResponse . setContent ( data ) ; return httpResponse ; }
Encodes the given response as a HTTP response message. This method is guaranteed not to throw.

@param response The response to encode.
@return The encoded response.