Package com.amazonaws.util.json

Examples of com.amazonaws.util.json.JSONWriter


            throw new IllegalArgumentException("Policy cannot be null");
        }

        StringWriter writer = new StringWriter();
        try {
            JSONWriter generator = new JSONWriter(writer);
            writePolicy(policy, generator);
            return writer.toString();
        } catch (Exception e) {
            String message = "Unable to serialize policy to JSON string: " + e.getMessage();
            throw new IllegalArgumentException(message, e);
View Full Code Here


            throw new IllegalArgumentException("Policy cannot be null");
        }

        StringWriter writer = new StringWriter();
        try {
            JSONWriter generator = new JSONWriter(writer);
            writePolicy(policy, generator);
            return writer.toString();
        } catch (Exception e) {
            String message = "Unable to serialize policy to JSON string: " + e.getMessage();
            throw new IllegalArgumentException(message, e);
View Full Code Here

            throw new IllegalArgumentException("Policy cannot be null");
        }

        StringWriter writer = new StringWriter();
        try {
            JSONWriter generator = new JSONWriter(writer);
            writePolicy(policy, generator);
            return writer.toString();
        } catch (Exception e) {
            String message = "Unable to serialize policy to JSON string: " + e.getMessage();
            throw new IllegalArgumentException(message, e);
View Full Code Here

            throw new IllegalArgumentException("Policy cannot be null");
        }

        StringWriter writer = new StringWriter();
        try {
            JSONWriter generator = new JSONWriter(writer);
            writePolicy(policy, generator);
            return writer.toString();
        } catch (Exception e) {
            String message = "Unable to serialize policy to JSON string: " + e.getMessage();
            throw new IllegalArgumentException(message, e);
View Full Code Here

            throw new IllegalArgumentException("Policy cannot be null");
        }

        StringWriter writer = new StringWriter();
        try {
            JSONWriter generator = new JSONWriter(writer);
            writePolicy(policy, generator);
            return writer.toString();
        } catch (Exception e) {
            String message = "Unable to serialize policy to JSON string: " + e.getMessage();
            throw new IllegalArgumentException(message, e);
View Full Code Here

            throw new IllegalArgumentException("Policy cannot be null");
        }

        StringWriter writer = new StringWriter();
        try {
            JSONWriter generator = new JSONWriter(writer);
            writePolicy(policy, generator);
            return writer.toString();
        } catch (Exception e) {
            String message = "Unable to serialize policy to JSON string: " + e.getMessage();
            throw new IllegalArgumentException(message, e);
View Full Code Here

            throw new IllegalArgumentException("Policy cannot be null");
        }

        StringWriter writer = new StringWriter();
        try {
            JSONWriter generator = new JSONWriter(writer);
            writePolicy(policy, generator);
            return writer.toString();
        } catch (Exception e) {
            String message = "Unable to serialize policy to JSON string: " + e.getMessage();
            throw new IllegalArgumentException(message, e);
View Full Code Here

      throw new AmazonClientException("Invalid argument passed to marshall(...)");
    }

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

            //Begin whole object containing responses and unprocessedItems.
      jsonWriter.object();

            //Begin response object
      jsonWriter.key("Responses").object();

      Map<String, BatchWriteResponse> responses = batchWriteItemResult.getResponses();

      if (responses != null) {
        for (String tableKey : responses.keySet()) {
                    //Begin table
          jsonWriter.key(tableKey).object();
                    Double consumedCapacityUnits = responses.get(tableKey).getConsumedCapacityUnits();
          if (consumedCapacityUnits != null) {
            jsonWriter.key("ConsumedCapacityUnits").value(consumedCapacityUnits);
          }
                    //End table
          jsonWriter.endObject();
        }
      }
            //End response
            jsonWriter.endObject();

            //Begin unprocessedItems
      jsonWriter.key("UnprocessedItems").object();
            Map<String, List<WriteRequest>> unprocessedItems = batchWriteItemResult.getUnprocessedItems();
            if (unprocessedItems != null) {
                for (String tableKey : unprocessedItems.keySet()) {
                    //begin table
                    jsonWriter.key(tableKey).array();
                    for (WriteRequest request : unprocessedItems.get(tableKey)) {
                        //begin each object of array
                        jsonWriter.object();
                        PutRequest putRequest = request.getPutRequest();
                        DeleteRequest deleteRequest = request.getDeleteRequest();
                        if (putRequest != null) {
                            //Begin put request
                            jsonWriter.key("PutRequest").object();
                            Map<String, AttributeValue> item = putRequest.getItem();
                            if (item != null) {
                                for (String itemKey : item.keySet()) {
                                    //begin attribute value
                                    jsonWriter.key(itemKey).object();
                                    AttributeValue value = item.get(itemKey);
                                    if (value.getN() != null) {
                                        jsonWriter.key("N").value(value.getN());
                                    } else if (value.getS() != null) {
                                        jsonWriter.key("S").value(value.getS());
                                    } else if (value.getB() != null) {
                                        jsonWriter.key("B").value(value.getS());
                                    } else if (value.getSS() != null) {
                                        jsonWriter.key("SS").value(value.getS());
                                    } else if (value.getNS() != null) {
                                        jsonWriter.key("NS").value(value.getNS());
                                    } else if (value.getBS() != null) {
                                        jsonWriter.key("BS").value(value.getSS());
                                    }
                                    //end attribute value
                                    jsonWriter.endObject();
                                }
                            }
                            //end put request
                            jsonWriter.endObject();
                        } else if (deleteRequest != null) {
                            //Begin delete request
                            jsonWriter.key("DeleteRequest").object();
                            Key key = deleteRequest.getKey();
                            if (key != null) {
                                //begin key
                                jsonWriter.key("Key").object();
                                AttributeValue hashKeyElemenet = key.getHashKeyElement();
                                AttributeValue rangeKeyElement = key.getRangeKeyElement();
                                if (hashKeyElemenet != null) {
                                    if (hashKeyElemenet.getN() != null) {
                                        jsonWriter.key("N").value(hashKeyElemenet.getN());
                                    } else if (hashKeyElemenet.getS() != null) {
                                        jsonWriter.key("S").value(hashKeyElemenet.getS());
                                    } else if (hashKeyElemenet.getB() != null) {
                                        jsonWriter.key("B").value(hashKeyElemenet.getS());
                                    } else if (hashKeyElemenet.getSS() != null) {
                                        jsonWriter.key("SS").value(hashKeyElemenet.getS());
                                    } else if (hashKeyElemenet.getNS() != null) {
                                        jsonWriter.key("NS").value(hashKeyElemenet.getNS());
                                    } else if (hashKeyElemenet.getBS() != null) {
                                        jsonWriter.key("BS").value(hashKeyElemenet.getSS());
                                    }
                                }
                                if (rangeKeyElement != null) {
                                    if (rangeKeyElement.getN() != null) {
                                        jsonWriter.key("N").value(rangeKeyElement.getN());
                                    } else if (rangeKeyElement.getS() != null) {
                                        jsonWriter.key("S").value(rangeKeyElement.getS());
                                    } else if (rangeKeyElement.getB() != null) {
                                        jsonWriter.key("B").value(rangeKeyElement.getS());
                                    } else if (rangeKeyElement.getSS() != null) {
                                        jsonWriter.key("SS").value(rangeKeyElement.getS());
                                    } else if (rangeKeyElement.getNS() != null) {
                                        jsonWriter.key("NS").value(rangeKeyElement.getNS());
                                    } else if (rangeKeyElement.getBS() != null) {
                                        jsonWriter.key("BS").value(rangeKeyElement.getSS());
                                    }
                                }
                                //end key
                                jsonWriter.endObject();
                            }
                            //End delete request
                            jsonWriter.endObject();
                        }
                        //end each object of array
                        jsonWriter.endObject();
                    }
                    //end table
                    jsonWriter.endArray();
                }
            }

            //End unprocessedItems
      jsonWriter.endObject();

            //End whole object containing responses and unprocessedItems.
      jsonWriter.endObject();

      return stringWriter.toString();
    } catch (Throwable t) {
      throw new AmazonClientException("Unable to marshall request to JSON: " + t.getMessage(), t);
    }
View Full Code Here

      throw new AmazonClientException("Invalid argument passed to marshall(...)");
    }

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

      TableDescription table = describeTableResult.getTable();
      if (table != null) {
        jsonWriter.key("Table").object();
        jsonWriter.key("ItemCount").value(table.getItemCount());
        jsonWriter.key("TableName").value(table.getTableName());
        jsonWriter.key("TableSizeBytes").value(table.getTableSizeBytes());
        jsonWriter.key("TableStatus").value(table.getTableStatus());
        jsonWriter.key("CreationDateTime").value(table.getCreationDateTime());

        KeySchema keySchema = table.getKeySchema();
        if (keySchema != null) {
          jsonWriter.key("KeySchema").object();
          KeySchemaElement hashKeyElement = keySchema.getHashKeyElement();
          if (hashKeyElement != null) {
            jsonWriter.key("HashKeyElement").object();
            if (hashKeyElement.getAttributeName() != null) {
              jsonWriter.key("AttributeName").value(hashKeyElement.getAttributeName());
            }
            if (hashKeyElement.getAttributeType() != null) {
              jsonWriter.key("AttributeType").value(hashKeyElement.getAttributeType());
            }
            jsonWriter.endObject();
          }

          KeySchemaElement rangeKeyElement = keySchema.getRangeKeyElement();
          if (rangeKeyElement != null) {
            jsonWriter.key("RangeKeyElement").object();
            if (rangeKeyElement.getAttributeName() != null) {
              jsonWriter.key("AttributeName").value(rangeKeyElement.getAttributeName());
            }
            if (rangeKeyElement.getAttributeType() != null) {
              jsonWriter.key("AttributeType").value(rangeKeyElement.getAttributeType());
            }
            jsonWriter.endObject();
          }
          jsonWriter.endObject();
        }

        ProvisionedThroughputDescription provisionedThroughput = table.getProvisionedThroughput();
        if (provisionedThroughput != null) {
          jsonWriter.key("ProvisionedThroughput").object();
          if (provisionedThroughput.getReadCapacityUnits() != null) {
            jsonWriter.key("ReadCapacityUnits").value(provisionedThroughput.getReadCapacityUnits());
          }
          if (provisionedThroughput.getWriteCapacityUnits() != null) {
            jsonWriter.key("WriteCapacityUnits").value(provisionedThroughput.getWriteCapacityUnits());
          }
          if (provisionedThroughput.getLastDecreaseDateTime() != null) {
            jsonWriter.key("LastDecreaseDateTime").value(provisionedThroughput.getLastDecreaseDateTime());
          }
          if (provisionedThroughput.getLastIncreaseDateTime() != null) {
            jsonWriter.key("LastIncreaseDateTime").value(provisionedThroughput.getLastIncreaseDateTime());
          }
          jsonWriter.endObject();
        }

        jsonWriter.endObject();
      }

      jsonWriter.endObject();

      return stringWriter.toString();
    } catch (Throwable t) {
      throw new AmazonClientException("Unable to marshall request to JSON: " + t.getMessage(), t);
    }
View Full Code Here

      throw new AmazonClientException("Invalid argument passed to marshall(...)");
    }

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

      TableDescription table = describeTableResult.getTableDescription();
      if (table != null) {
        jsonWriter.key("TableDescription").object();
        jsonWriter.key("TableName").value(table.getTableName());
        jsonWriter.key("TableStatus").value(table.getTableStatus());
        jsonWriter.key("CreationDateTime").value(table.getCreationDateTime());

        KeySchema keySchema = table.getKeySchema();
        if (keySchema != null) {
          jsonWriter.key("KeySchema").object();
          KeySchemaElement hashKeyElement = keySchema.getHashKeyElement();
          if (hashKeyElement != null) {
            jsonWriter.key("HashKeyElement").object();
            if (hashKeyElement.getAttributeName() != null) {
              jsonWriter.key("AttributeName").value(hashKeyElement.getAttributeName());
            }
            if (hashKeyElement.getAttributeType() != null) {
              jsonWriter.key("AttributeType").value(hashKeyElement.getAttributeType());
            }
            jsonWriter.endObject();
          }

          KeySchemaElement rangeKeyElement = keySchema.getRangeKeyElement();
          if (rangeKeyElement != null) {
            jsonWriter.key("RangeKeyElement").object();
            if (rangeKeyElement.getAttributeName() != null) {
              jsonWriter.key("AttributeName").value(rangeKeyElement.getAttributeName());
            }
            if (rangeKeyElement.getAttributeType() != null) {
              jsonWriter.key("AttributeType").value(rangeKeyElement.getAttributeType());
            }
            jsonWriter.endObject();
          }
          jsonWriter.endObject();
        }

        ProvisionedThroughputDescription provisionedThroughput = table.getProvisionedThroughput();
        if (provisionedThroughput != null) {
          jsonWriter.key("ProvisionedThroughput").object();
          if (provisionedThroughput.getReadCapacityUnits() != null) {
            jsonWriter.key("ReadCapacityUnits").value(provisionedThroughput.getReadCapacityUnits());
          }
          if (provisionedThroughput.getWriteCapacityUnits() != null) {
            jsonWriter.key("WriteCapacityUnits").value(provisionedThroughput.getWriteCapacityUnits());
          }
          if (provisionedThroughput.getLastDecreaseDateTime() != null) {
            jsonWriter.key("LastDecreaseDateTime").value(provisionedThroughput.getLastDecreaseDateTime());
          }
          if (provisionedThroughput.getLastIncreaseDateTime() != null) {
            jsonWriter.key("LastIncreaseDateTime").value(provisionedThroughput.getLastIncreaseDateTime());
          }
          jsonWriter.endObject();
        }

        jsonWriter.endObject();
      }

      jsonWriter.endObject();

      return stringWriter.toString();
    } catch (Throwable t) {
      throw new AmazonClientException("Unable to marshall request to JSON: " + t.getMessage(), t);
    }
View Full Code Here

TOP

Related Classes of com.amazonaws.util.json.JSONWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.