public Request<UpdateStackRequest> marshall(UpdateStackRequest updateStackRequest) {
    if (updateStackRequest == null) {
      throw new AmazonClientException("Invalid argument passed to marshall(...)");
    }

    Request<UpdateStackRequest> request =
        new DefaultRequest<UpdateStackRequest>(updateStackRequest, "AWSOpsWorks");
    String target = "OpsWorks_20130218.UpdateStack";
    request.addHeader("X-Amz-Target", target);

    request.setHttpMethod(HttpMethodName.POST);
    request.setResourcePath("");

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

      jsonWriter.object();

      if (updateStackRequest.getStackId() != null) {
        jsonWriter.key("StackId").value(updateStackRequest.getStackId());
      }
      if (updateStackRequest.getName() != null) {
        jsonWriter.key("Name").value(updateStackRequest.getName());
      }
      if (updateStackRequest.getAttributes() != null) {
        jsonWriter.key("Attributes");
        jsonWriter.object();
        for (Map.Entry<String, String> attributesListValue :
            updateStackRequest.getAttributes().entrySet()) {
          if (attributesListValue.getValue() != null) {
            jsonWriter.key(attributesListValue.getKey());

            jsonWriter.value(attributesListValue.getValue());
          }
        }
        jsonWriter.endObject();
      }
      if (updateStackRequest.getServiceRoleArn() != null) {
        jsonWriter.key("ServiceRoleArn").value(updateStackRequest.getServiceRoleArn());
      }
      if (updateStackRequest.getDefaultInstanceProfileArn() != null) {
        jsonWriter
            .key("DefaultInstanceProfileArn")
            .value(updateStackRequest.getDefaultInstanceProfileArn());
      }
      if (updateStackRequest.getDefaultOs() != null) {
        jsonWriter.key("DefaultOs").value(updateStackRequest.getDefaultOs());
      }
      if (updateStackRequest.getHostnameTheme() != null) {
        jsonWriter.key("HostnameTheme").value(updateStackRequest.getHostnameTheme());
      }
      if (updateStackRequest.getDefaultAvailabilityZone() != null) {
        jsonWriter
            .key("DefaultAvailabilityZone")
            .value(updateStackRequest.getDefaultAvailabilityZone());
      }
      if (updateStackRequest.getDefaultSubnetId() != null) {
        jsonWriter.key("DefaultSubnetId").value(updateStackRequest.getDefaultSubnetId());
      }
      if (updateStackRequest.getCustomJson() != null) {
        jsonWriter.key("CustomJson").value(updateStackRequest.getCustomJson());
      }
      StackConfigurationManager configurationManager = updateStackRequest.getConfigurationManager();
      if (configurationManager != null) {

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

        if (configurationManager.getName() != null) {
          jsonWriter.key("Name").value(configurationManager.getName());
        }
        if (configurationManager.getVersion() != null) {
          jsonWriter.key("Version").value(configurationManager.getVersion());
        }
        jsonWriter.endObject();
      }
      ChefConfiguration chefConfiguration = updateStackRequest.getChefConfiguration();
      if (chefConfiguration != null) {

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

        if (chefConfiguration.isManageBerkshelf() != null) {
          jsonWriter.key("ManageBerkshelf").value(chefConfiguration.isManageBerkshelf());
        }
        if (chefConfiguration.getBerkshelfVersion() != null) {
          jsonWriter.key("BerkshelfVersion").value(chefConfiguration.getBerkshelfVersion());
        }
        jsonWriter.endObject();
      }
      if (updateStackRequest.isUseCustomCookbooks() != null) {
        jsonWriter.key("UseCustomCookbooks").value(updateStackRequest.isUseCustomCookbooks());
      }
      Source customCookbooksSource = updateStackRequest.getCustomCookbooksSource();
      if (customCookbooksSource != null) {

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

        if (customCookbooksSource.getType() != null) {
          jsonWriter.key("Type").value(customCookbooksSource.getType());
        }
        if (customCookbooksSource.getUrl() != null) {
          jsonWriter.key("Url").value(customCookbooksSource.getUrl());
        }
        if (customCookbooksSource.getUsername() != null) {
          jsonWriter.key("Username").value(customCookbooksSource.getUsername());
        }
        if (customCookbooksSource.getPassword() != null) {
          jsonWriter.key("Password").value(customCookbooksSource.getPassword());
        }
        if (customCookbooksSource.getSshKey() != null) {
          jsonWriter.key("SshKey").value(customCookbooksSource.getSshKey());
        }
        if (customCookbooksSource.getRevision() != null) {
          jsonWriter.key("Revision").value(customCookbooksSource.getRevision());
        }
        jsonWriter.endObject();
      }
      if (updateStackRequest.getDefaultSshKeyName() != null) {
        jsonWriter.key("DefaultSshKeyName").value(updateStackRequest.getDefaultSshKeyName());
      }
      if (updateStackRequest.getDefaultRootDeviceType() != null) {
        jsonWriter
            .key("DefaultRootDeviceType")
            .value(updateStackRequest.getDefaultRootDeviceType());
      }
      if (updateStackRequest.isUseOpsworksSecurityGroups() != null) {
        jsonWriter
            .key("UseOpsworksSecurityGroups")
            .value(updateStackRequest.isUseOpsworksSecurityGroups());
      }
      if (updateStackRequest.getAgentVersion() != null) {
        jsonWriter.key("AgentVersion").value(updateStackRequest.getAgentVersion());
      }

      jsonWriter.endObject();

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

    return request;
  }
  public Request<CreateDeploymentRequest> marshall(
      CreateDeploymentRequest createDeploymentRequest) {
    if (createDeploymentRequest == null) {
      throw new AmazonClientException("Invalid argument passed to marshall(...)");
    }

    Request<CreateDeploymentRequest> request =
        new DefaultRequest<CreateDeploymentRequest>(createDeploymentRequest, "AWSOpsWorks");
    String target = "OpsWorks_20130218.CreateDeployment";
    request.addHeader("X-Amz-Target", target);
    request.addHeader("Content-Type", "application/x-amz-json-1.1");

    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 (createDeploymentRequest.getStackId() != null) {
        jsonWriter.key("StackId").value(createDeploymentRequest.getStackId());
      }
      if (createDeploymentRequest.getAppId() != null) {
        jsonWriter.key("AppId").value(createDeploymentRequest.getAppId());
      }

      java.util.List<String> instanceIdsList = createDeploymentRequest.getInstanceIds();
      if (instanceIdsList != null && instanceIdsList.size() > 0) {

        jsonWriter.key("InstanceIds");
        jsonWriter.array();

        for (String instanceIdsListValue : instanceIdsList) {
          if (instanceIdsListValue != null) {
            jsonWriter.value(instanceIdsListValue);
          }
        }
        jsonWriter.endArray();
      }
      DeploymentCommand command = createDeploymentRequest.getCommand();
      if (command != null) {

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

        if (command.getName() != null) {
          jsonWriter.key("Name").value(command.getName());
        }
        if (command.getArgs() != null) {
          jsonWriter.key("Args");
          jsonWriter.object();
          for (Map.Entry<String, java.util.List<String>> argsListValue :
              command.getArgs().entrySet()) {
            if (argsListValue.getValue() != null) {
              jsonWriter.key(argsListValue.getKey());
            }
          }
          jsonWriter.endObject();
        }
        jsonWriter.endObject();
      }
      if (createDeploymentRequest.getComment() != null) {
        jsonWriter.key("Comment").value(createDeploymentRequest.getComment());
      }
      if (createDeploymentRequest.getCustomJson() != null) {
        jsonWriter.key("CustomJson").value(createDeploymentRequest.getCustomJson());
      }

      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;
  }
  public Request<DescribeTimeBasedAutoScalingRequest> marshall(
      DescribeTimeBasedAutoScalingRequest describeTimeBasedAutoScalingRequest) {
    if (describeTimeBasedAutoScalingRequest == null) {
      throw new AmazonClientException("Invalid argument passed to marshall(...)");
    }

    Request<DescribeTimeBasedAutoScalingRequest> request =
        new DefaultRequest<DescribeTimeBasedAutoScalingRequest>(
            describeTimeBasedAutoScalingRequest, "AWSOpsWorks");
    String target = "OpsWorks_20130218.DescribeTimeBasedAutoScaling";
    request.addHeader("X-Amz-Target", target);
    request.addHeader("Content-Type", "application/x-amz-json-1.1");

    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();

      java.util.List<String> instanceIdsList = describeTimeBasedAutoScalingRequest.getInstanceIds();
      if (instanceIdsList != null) {

        jsonWriter.key("InstanceIds");
        jsonWriter.array();

        for (String instanceIdsListValue : instanceIdsList) {
          if (instanceIdsListValue != null) {
            jsonWriter.value(instanceIdsListValue);
          }
        }
        jsonWriter.endArray();
      }

      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;
  }
  public Request<CreateStackRequest> marshall(CreateStackRequest createStackRequest) {
    if (createStackRequest == null) {
      throw new AmazonClientException("Invalid argument passed to marshall(...)");
    }

    Request<CreateStackRequest> request =
        new DefaultRequest<CreateStackRequest>(createStackRequest, "AWSOpsWorks");
    String target = "OpsWorks_20130218.CreateStack";
    request.addHeader("X-Amz-Target", target);
    request.addHeader("Content-Type", "application/x-amz-json-1.1");

    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 (createStackRequest.getName() != null) {
        jsonWriter.key("Name").value(createStackRequest.getName());
      }
      if (createStackRequest.getRegion() != null) {
        jsonWriter.key("Region").value(createStackRequest.getRegion());
      }
      if (createStackRequest.getVpcId() != null) {
        jsonWriter.key("VpcId").value(createStackRequest.getVpcId());
      }
      if (createStackRequest.getAttributes() != null) {
        jsonWriter.key("Attributes");
        jsonWriter.object();
        for (Map.Entry<String, String> attributesListValue :
            createStackRequest.getAttributes().entrySet()) {
          if (attributesListValue.getValue() != null) {
            jsonWriter.key(attributesListValue.getKey());

            jsonWriter.value(attributesListValue.getValue());
          }
        }
        jsonWriter.endObject();
      }
      if (createStackRequest.getServiceRoleArn() != null) {
        jsonWriter.key("ServiceRoleArn").value(createStackRequest.getServiceRoleArn());
      }
      if (createStackRequest.getDefaultInstanceProfileArn() != null) {
        jsonWriter
            .key("DefaultInstanceProfileArn")
            .value(createStackRequest.getDefaultInstanceProfileArn());
      }
      if (createStackRequest.getDefaultOs() != null) {
        jsonWriter.key("DefaultOs").value(createStackRequest.getDefaultOs());
      }
      if (createStackRequest.getHostnameTheme() != null) {
        jsonWriter.key("HostnameTheme").value(createStackRequest.getHostnameTheme());
      }
      if (createStackRequest.getDefaultAvailabilityZone() != null) {
        jsonWriter
            .key("DefaultAvailabilityZone")
            .value(createStackRequest.getDefaultAvailabilityZone());
      }
      if (createStackRequest.getDefaultSubnetId() != null) {
        jsonWriter.key("DefaultSubnetId").value(createStackRequest.getDefaultSubnetId());
      }
      if (createStackRequest.getCustomJson() != null) {
        jsonWriter.key("CustomJson").value(createStackRequest.getCustomJson());
      }
      StackConfigurationManager configurationManager = createStackRequest.getConfigurationManager();
      if (configurationManager != null) {

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

        if (configurationManager.getName() != null) {
          jsonWriter.key("Name").value(configurationManager.getName());
        }
        if (configurationManager.getVersion() != null) {
          jsonWriter.key("Version").value(configurationManager.getVersion());
        }
        jsonWriter.endObject();
      }
      if (createStackRequest.isUseCustomCookbooks() != null) {
        jsonWriter.key("UseCustomCookbooks").value(createStackRequest.isUseCustomCookbooks());
      }
      Source customCookbooksSource = createStackRequest.getCustomCookbooksSource();
      if (customCookbooksSource != null) {

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

        if (customCookbooksSource.getType() != null) {
          jsonWriter.key("Type").value(customCookbooksSource.getType());
        }
        if (customCookbooksSource.getUrl() != null) {
          jsonWriter.key("Url").value(customCookbooksSource.getUrl());
        }
        if (customCookbooksSource.getUsername() != null) {
          jsonWriter.key("Username").value(customCookbooksSource.getUsername());
        }
        if (customCookbooksSource.getPassword() != null) {
          jsonWriter.key("Password").value(customCookbooksSource.getPassword());
        }
        if (customCookbooksSource.getSshKey() != null) {
          jsonWriter.key("SshKey").value(customCookbooksSource.getSshKey());
        }
        if (customCookbooksSource.getRevision() != null) {
          jsonWriter.key("Revision").value(customCookbooksSource.getRevision());
        }
        jsonWriter.endObject();
      }
      if (createStackRequest.getDefaultSshKeyName() != null) {
        jsonWriter.key("DefaultSshKeyName").value(createStackRequest.getDefaultSshKeyName());
      }
      if (createStackRequest.getDefaultRootDeviceType() != null) {
        jsonWriter
            .key("DefaultRootDeviceType")
            .value(createStackRequest.getDefaultRootDeviceType());
      }

      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;
  }
  public Request<CreateInstanceRequest> marshall(CreateInstanceRequest createInstanceRequest) {
    if (createInstanceRequest == null) {
      throw new AmazonClientException("Invalid argument passed to marshall(...)");
    }

    Request<CreateInstanceRequest> request =
        new DefaultRequest<CreateInstanceRequest>(createInstanceRequest, "AWSOpsWorks");
    String target = "OpsWorks_20130218.CreateInstance";
    request.addHeader("X-Amz-Target", target);

    request.setHttpMethod(HttpMethodName.POST);
    request.setResourcePath("");

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

      jsonWriter.object();

      if (createInstanceRequest.getStackId() != null) {
        jsonWriter.key("StackId").value(createInstanceRequest.getStackId());
      }

      com.amazonaws.internal.ListWithAutoConstructFlag<String> layerIdsList =
          (com.amazonaws.internal.ListWithAutoConstructFlag<String>)
              (createInstanceRequest.getLayerIds());
      if (layerIdsList != null && !(layerIdsList.isAutoConstruct() && layerIdsList.isEmpty())) {

        jsonWriter.key("LayerIds");
        jsonWriter.array();

        for (String layerIdsListValue : layerIdsList) {
          if (layerIdsListValue != null) {
            jsonWriter.value(layerIdsListValue);
          }
        }
        jsonWriter.endArray();
      }
      if (createInstanceRequest.getInstanceType() != null) {
        jsonWriter.key("InstanceType").value(createInstanceRequest.getInstanceType());
      }
      if (createInstanceRequest.getAutoScalingType() != null) {
        jsonWriter.key("AutoScalingType").value(createInstanceRequest.getAutoScalingType());
      }
      if (createInstanceRequest.getHostname() != null) {
        jsonWriter.key("Hostname").value(createInstanceRequest.getHostname());
      }
      if (createInstanceRequest.getOs() != null) {
        jsonWriter.key("Os").value(createInstanceRequest.getOs());
      }
      if (createInstanceRequest.getAmiId() != null) {
        jsonWriter.key("AmiId").value(createInstanceRequest.getAmiId());
      }
      if (createInstanceRequest.getSshKeyName() != null) {
        jsonWriter.key("SshKeyName").value(createInstanceRequest.getSshKeyName());
      }
      if (createInstanceRequest.getAvailabilityZone() != null) {
        jsonWriter.key("AvailabilityZone").value(createInstanceRequest.getAvailabilityZone());
      }
      if (createInstanceRequest.getVirtualizationType() != null) {
        jsonWriter.key("VirtualizationType").value(createInstanceRequest.getVirtualizationType());
      }
      if (createInstanceRequest.getSubnetId() != null) {
        jsonWriter.key("SubnetId").value(createInstanceRequest.getSubnetId());
      }
      if (createInstanceRequest.getArchitecture() != null) {
        jsonWriter.key("Architecture").value(createInstanceRequest.getArchitecture());
      }
      if (createInstanceRequest.getRootDeviceType() != null) {
        jsonWriter.key("RootDeviceType").value(createInstanceRequest.getRootDeviceType());
      }

      com.amazonaws.internal.ListWithAutoConstructFlag<BlockDeviceMapping> blockDeviceMappingsList =
          (com.amazonaws.internal.ListWithAutoConstructFlag<BlockDeviceMapping>)
              (createInstanceRequest.getBlockDeviceMappings());
      if (blockDeviceMappingsList != null
          && !(blockDeviceMappingsList.isAutoConstruct() && blockDeviceMappingsList.isEmpty())) {

        jsonWriter.key("BlockDeviceMappings");
        jsonWriter.array();

        for (BlockDeviceMapping blockDeviceMappingsListValue : blockDeviceMappingsList) {
          if (blockDeviceMappingsListValue != null) {
            jsonWriter.object();
            if (blockDeviceMappingsListValue.getDeviceName() != null) {
              jsonWriter.key("DeviceName").value(blockDeviceMappingsListValue.getDeviceName());
            }
            if (blockDeviceMappingsListValue.getNoDevice() != null) {
              jsonWriter.key("NoDevice").value(blockDeviceMappingsListValue.getNoDevice());
            }
            if (blockDeviceMappingsListValue.getVirtualName() != null) {
              jsonWriter.key("VirtualName").value(blockDeviceMappingsListValue.getVirtualName());
            }
            EbsBlockDevice ebs = blockDeviceMappingsListValue.getEbs();
            if (ebs != null) {

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

              if (ebs.getSnapshotId() != null) {
                jsonWriter.key("SnapshotId").value(ebs.getSnapshotId());
              }
              if (ebs.getIops() != null) {
                jsonWriter.key("Iops").value(ebs.getIops());
              }
              if (ebs.getVolumeSize() != null) {
                jsonWriter.key("VolumeSize").value(ebs.getVolumeSize());
              }
              if (ebs.getVolumeType() != null) {
                jsonWriter.key("VolumeType").value(ebs.getVolumeType());
              }
              if (ebs.isDeleteOnTermination() != null) {
                jsonWriter.key("DeleteOnTermination").value(ebs.isDeleteOnTermination());
              }
              jsonWriter.endObject();
            }
            jsonWriter.endObject();
          }
        }
        jsonWriter.endArray();
      }
      if (createInstanceRequest.isInstallUpdatesOnBoot() != null) {
        jsonWriter
            .key("InstallUpdatesOnBoot")
            .value(createInstanceRequest.isInstallUpdatesOnBoot());
      }
      if (createInstanceRequest.isEbsOptimized() != null) {
        jsonWriter.key("EbsOptimized").value(createInstanceRequest.isEbsOptimized());
      }
      if (createInstanceRequest.getAgentVersion() != null) {
        jsonWriter.key("AgentVersion").value(createInstanceRequest.getAgentVersion());
      }

      jsonWriter.endObject();

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

    return request;
  }
  public Request<UpdateInstanceRequest> marshall(UpdateInstanceRequest updateInstanceRequest) {
    if (updateInstanceRequest == null) {
      throw new AmazonClientException("Invalid argument passed to marshall(...)");
    }

    Request<UpdateInstanceRequest> request =
        new DefaultRequest<UpdateInstanceRequest>(updateInstanceRequest, "AWSOpsWorks");
    String target = "OpsWorks_20130218.UpdateInstance";
    request.addHeader("X-Amz-Target", target);

    request.setHttpMethod(HttpMethodName.POST);
    request.setResourcePath("");

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

      jsonWriter.object();

      if (updateInstanceRequest.getInstanceId() != null) {
        jsonWriter.key("InstanceId").value(updateInstanceRequest.getInstanceId());
      }

      com.amazonaws.internal.ListWithAutoConstructFlag<String> layerIdsList =
          (com.amazonaws.internal.ListWithAutoConstructFlag<String>)
              (updateInstanceRequest.getLayerIds());
      if (layerIdsList != null && !(layerIdsList.isAutoConstruct() && layerIdsList.isEmpty())) {

        jsonWriter.key("LayerIds");
        jsonWriter.array();

        for (String layerIdsListValue : layerIdsList) {
          if (layerIdsListValue != null) {
            jsonWriter.value(layerIdsListValue);
          }
        }
        jsonWriter.endArray();
      }
      if (updateInstanceRequest.getInstanceType() != null) {
        jsonWriter.key("InstanceType").value(updateInstanceRequest.getInstanceType());
      }
      if (updateInstanceRequest.getAutoScalingType() != null) {
        jsonWriter.key("AutoScalingType").value(updateInstanceRequest.getAutoScalingType());
      }
      if (updateInstanceRequest.getHostname() != null) {
        jsonWriter.key("Hostname").value(updateInstanceRequest.getHostname());
      }
      if (updateInstanceRequest.getOs() != null) {
        jsonWriter.key("Os").value(updateInstanceRequest.getOs());
      }
      if (updateInstanceRequest.getAmiId() != null) {
        jsonWriter.key("AmiId").value(updateInstanceRequest.getAmiId());
      }
      if (updateInstanceRequest.getSshKeyName() != null) {
        jsonWriter.key("SshKeyName").value(updateInstanceRequest.getSshKeyName());
      }
      if (updateInstanceRequest.getArchitecture() != null) {
        jsonWriter.key("Architecture").value(updateInstanceRequest.getArchitecture());
      }
      if (updateInstanceRequest.isInstallUpdatesOnBoot() != null) {
        jsonWriter
            .key("InstallUpdatesOnBoot")
            .value(updateInstanceRequest.isInstallUpdatesOnBoot());
      }
      if (updateInstanceRequest.isEbsOptimized() != null) {
        jsonWriter.key("EbsOptimized").value(updateInstanceRequest.isEbsOptimized());
      }

      jsonWriter.endObject();

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

    return request;
  }