try {
StringWriter stringWriter = new StringWriter();
JSONWriter jsonWriter = new JSONWriter(stringWriter);
jsonWriter.object();
TableDescription table = createTableResult.getTableDescription();
if (table != null) {
jsonWriter.key("TableDescription").object();
if (table.getCreationDateTime() != null) {
jsonWriter.key("CreationDateTime").value(table.getCreationDateTime());
}
if (table.getTableName() != null) {
jsonWriter.key("TableName").value(table.getTableName());
}
if (table.getTableStatus() != null) {
jsonWriter.key("TableStatus").value(table.getTableStatus());
}
List<AttributeDefinition> attributes = table.getAttributeDefinitions();
if (attributes != null) {
jsonWriter.key("AttributeDefinitions").array();
for (AttributeDefinition attr : attributes) {
jsonWriter.object();
if (attr.getAttributeName() != null) {
jsonWriter.key("AttributeName").value(attr.getAttributeName());
}
if (attr.getAttributeType() != null) {
jsonWriter.key("AttributeType").value(attr.getAttributeType());
}
jsonWriter.endObject(); // AttributeDefinition
}
jsonWriter.endArray(); // AttributeDefinitions
}
List<KeySchemaElement> keySchema = table.getKeySchema();
if (keySchema != null) {
jsonWriter.key("KeySchema").array();
for (KeySchemaElement element : keySchema) {
jsonWriter.object();
if (element.getAttributeName() != null) {
jsonWriter.key("AttributeName").value(element.getAttributeName());
}
if (element.getKeyType() != null) {
jsonWriter.key("KeyType").value(element.getKeyType());
}
jsonWriter.endObject(); // KeySchemaElement
}
jsonWriter.endArray(); //KeySchema
}
ProvisionedThroughputDescription provisionedThroughput = table.getProvisionedThroughput();
if (provisionedThroughput != null) {
jsonWriter.key("ProvisionedThroughput").object();
if (provisionedThroughput.getReadCapacityUnits() != null) {
jsonWriter.key("ReadCapacityUnits").value(provisionedThroughput.getReadCapacityUnits());
}