/** Marshall the given parameter object, and output to a JSONWriter */ public void marshall(PutEventsRequestEntry putEventsRequestEntry, JSONWriter jsonWriter) { if (putEventsRequestEntry == null) { throw new AmazonClientException("Invalid argument passed to marshall(...)"); } try { jsonWriter.object(); if (putEventsRequestEntry.getTime() != null) { jsonWriter.key("Time").value(putEventsRequestEntry.getTime()); } if (putEventsRequestEntry.getSource() != null) { jsonWriter.key("Source").value(putEventsRequestEntry.getSource()); } java.util.List<String> resourcesList = putEventsRequestEntry.getResources(); if (resourcesList != null) { jsonWriter.key("Resources"); jsonWriter.array(); for (String resourcesListValue : resourcesList) { if (resourcesListValue != null) { jsonWriter.value(resourcesListValue); } } jsonWriter.endArray(); } if (putEventsRequestEntry.getDetailType() != null) { jsonWriter.key("DetailType").value(putEventsRequestEntry.getDetailType()); } if (putEventsRequestEntry.getDetail() != null) { jsonWriter.key("Detail").value(putEventsRequestEntry.getDetail()); } jsonWriter.endObject(); } catch (Throwable t) { throw new AmazonClientException("Unable to marshall request to JSON: " + t.getMessage(), t); } }
public Request<PutEventsRequest> marshall(PutEventsRequest putEventsRequest) { if (putEventsRequest == null) { throw new AmazonClientException("Invalid argument passed to marshall(...)"); } Request<PutEventsRequest> request = new DefaultRequest<PutEventsRequest>(putEventsRequest, "AmazonCloudWatchEvents"); request.addHeader("X-Amz-Target", "AWSEvents.PutEvents"); request.setHttpMethod(HttpMethodName.POST); request.setResourcePath(""); try { StringWriter stringWriter = new StringWriter(); JSONWriter jsonWriter = new JSONWriter(stringWriter); jsonWriter.object(); java.util.List<PutEventsRequestEntry> entriesList = putEventsRequest.getEntries(); if (entriesList != null) { jsonWriter.key("Entries"); jsonWriter.array(); for (PutEventsRequestEntry entriesListValue : entriesList) { if (entriesListValue != null) { PutEventsRequestEntryJsonMarshaller.getInstance() .marshall(entriesListValue, jsonWriter); } } jsonWriter.endArray(); } 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; }