/** Marshall the given parameter object, and output to a SdkJsonGenerator */
  public void marshall(
      ExecutionTimeFilter executionTimeFilter, StructuredJsonGenerator jsonGenerator) {

    if (executionTimeFilter == null) {
      throw new AmazonClientException("Invalid argument passed to marshall(...)");
    }

    try {
      jsonGenerator.writeStartObject();

      if (executionTimeFilter.getOldestDate() != null) {
        jsonGenerator.writeFieldName("oldestDate").writeValue(executionTimeFilter.getOldestDate());
      }
      if (executionTimeFilter.getLatestDate() != null) {
        jsonGenerator.writeFieldName("latestDate").writeValue(executionTimeFilter.getLatestDate());
      }

      jsonGenerator.writeEndObject();
    } catch (Throwable t) {
      throw new AmazonClientException("Unable to marshall request to JSON: " + t.getMessage(), t);
    }
  }
  public Request<ListClosedWorkflowExecutionsRequest> marshall(
      ListClosedWorkflowExecutionsRequest listClosedWorkflowExecutionsRequest) {
    if (listClosedWorkflowExecutionsRequest == null) {
      throw new AmazonClientException("Invalid argument passed to marshall(...)");
    }

    Request<ListClosedWorkflowExecutionsRequest> request =
        new DefaultRequest<ListClosedWorkflowExecutionsRequest>(
            listClosedWorkflowExecutionsRequest, "AmazonSimpleWorkflow");
    String target = "SimpleWorkflowService.ListClosedWorkflowExecutions";
    request.addHeader("X-Amz-Target", target);
    request.addHeader("Content-Type", "application/x-amz-json-1.0");

    request.setHttpMethod(HttpMethodName.POST);

    String uriResourcePath = "";

    uriResourcePath = uriResourcePath.replaceAll("//", "/");

    if (uriResourcePath.contains("?")) {
      String queryString = uriResourcePath.substring(uriResourcePath.indexOf("?") + 1);
      uriResourcePath = uriResourcePath.substring(0, uriResourcePath.indexOf("?"));

      for (String s : queryString.split("[;&]")) {
        String[] nameValuePair = s.split("=");
        if (nameValuePair.length == 2) {
          request.addParameter(nameValuePair[0], nameValuePair[1]);
        } else {
          request.addParameter(s, null);
        }
      }
    }

    request.setResourcePath(uriResourcePath);

    try {
      StringWriter stringWriter = new StringWriter();
      JSONWriter jsonWriter = new JSONWriter(stringWriter);

      jsonWriter.object();

      if (listClosedWorkflowExecutionsRequest.getDomain() != null) {
        jsonWriter.key("domain").value(listClosedWorkflowExecutionsRequest.getDomain());
      }
      ExecutionTimeFilter startTimeFilter =
          listClosedWorkflowExecutionsRequest.getStartTimeFilter();
      if (startTimeFilter != null) {

        jsonWriter.key("startTimeFilter");
        jsonWriter.object();

        if (startTimeFilter.getOldestDate() != null) {
          jsonWriter.key("oldestDate").value(startTimeFilter.getOldestDate());
        }
        if (startTimeFilter.getLatestDate() != null) {
          jsonWriter.key("latestDate").value(startTimeFilter.getLatestDate());
        }
        jsonWriter.endObject();
      }
      ExecutionTimeFilter closeTimeFilter =
          listClosedWorkflowExecutionsRequest.getCloseTimeFilter();
      if (closeTimeFilter != null) {

        jsonWriter.key("closeTimeFilter");
        jsonWriter.object();

        if (closeTimeFilter.getOldestDate() != null) {
          jsonWriter.key("oldestDate").value(closeTimeFilter.getOldestDate());
        }
        if (closeTimeFilter.getLatestDate() != null) {
          jsonWriter.key("latestDate").value(closeTimeFilter.getLatestDate());
        }
        jsonWriter.endObject();
      }
      WorkflowExecutionFilter executionFilter =
          listClosedWorkflowExecutionsRequest.getExecutionFilter();
      if (executionFilter != null) {

        jsonWriter.key("executionFilter");
        jsonWriter.object();

        if (executionFilter.getWorkflowId() != null) {
          jsonWriter.key("workflowId").value(executionFilter.getWorkflowId());
        }
        jsonWriter.endObject();
      }
      CloseStatusFilter closeStatusFilter =
          listClosedWorkflowExecutionsRequest.getCloseStatusFilter();
      if (closeStatusFilter != null) {

        jsonWriter.key("closeStatusFilter");
        jsonWriter.object();

        if (closeStatusFilter.getStatus() != null) {
          jsonWriter.key("status").value(closeStatusFilter.getStatus());
        }
        jsonWriter.endObject();
      }
      WorkflowTypeFilter typeFilter = listClosedWorkflowExecutionsRequest.getTypeFilter();
      if (typeFilter != null) {

        jsonWriter.key("typeFilter");
        jsonWriter.object();

        if (typeFilter.getName() != null) {
          jsonWriter.key("name").value(typeFilter.getName());
        }
        if (typeFilter.getVersion() != null) {
          jsonWriter.key("version").value(typeFilter.getVersion());
        }
        jsonWriter.endObject();
      }
      TagFilter tagFilter = listClosedWorkflowExecutionsRequest.getTagFilter();
      if (tagFilter != null) {

        jsonWriter.key("tagFilter");
        jsonWriter.object();

        if (tagFilter.getTag() != null) {
          jsonWriter.key("tag").value(tagFilter.getTag());
        }
        jsonWriter.endObject();
      }
      if (listClosedWorkflowExecutionsRequest.getNextPageToken() != null) {
        jsonWriter
            .key("nextPageToken")
            .value(listClosedWorkflowExecutionsRequest.getNextPageToken());
      }
      if (listClosedWorkflowExecutionsRequest.getMaximumPageSize() != null) {
        jsonWriter
            .key("maximumPageSize")
            .value(listClosedWorkflowExecutionsRequest.getMaximumPageSize());
      }
      if (listClosedWorkflowExecutionsRequest.isReverseOrder() != null) {
        jsonWriter.key("reverseOrder").value(listClosedWorkflowExecutionsRequest.isReverseOrder());
      }

      jsonWriter.endObject();

      String snippet = stringWriter.toString();
      byte[] content = snippet.getBytes("UTF-8");
      request.setContent(new StringInputStream(snippet));
      request.addHeader("Content-Length", Integer.toString(content.length));
    } catch (Throwable t) {
      throw new AmazonClientException("Unable to marshall request to JSON: " + t.getMessage(), t);
    }

    return request;
  }