use of com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.DynamoDBList in project aws-sdk-android by aws-amplify.
the class JsonUtils method toEntry.
private static DynamoDBEntry toEntry(JsonElement data) {
if (data == null || data.isJsonNull()) {
return DynamoDBNull.NULL;
}
if (data.isJsonObject()) {
final Document doc = new Document();
for (final Entry<String, JsonElement> entry : data.getAsJsonObject().entrySet()) {
final String key = entry.getKey();
final JsonElement element = entry.getValue();
doc.put(key, toEntry(element));
}
return doc;
}
if (data.isJsonArray()) {
final DynamoDBList list = new DynamoDBList();
final JsonArray array = data.getAsJsonArray();
for (final Iterator<JsonElement> iterator = array.iterator(); iterator.hasNext(); ) {
final JsonElement type = iterator.next();
list.add(toEntry(type));
}
return list;
}
final JsonPrimitive primitive = data.getAsJsonPrimitive();
if (primitive.isBoolean()) {
return new DynamoDBBool(primitive.getAsBoolean());
}
if (primitive.isString()) {
return new Primitive(primitive.getAsString());
}
if (primitive.isNumber()) {
return new Primitive(primitive.getAsNumber());
}
throw new JsonParseException("unable to parse json for key " + data.toString());
}
use of com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.DynamoDBList in project aws-sdk-android by aws-amplify.
the class JsonUtils method writeJson.
private static void writeJson(DynamoDBEntry entry, JsonWriter writer) throws IOException {
if (entry instanceof Document) {
writer.beginObject();
final Document doc = (Document) entry;
for (final Entry<String, DynamoDBEntry> docEntry : doc.entrySet()) {
final String key = docEntry.getKey();
final DynamoDBEntry value = docEntry.getValue();
writer.name(key);
writeJson(value, writer);
}
writer.endObject();
return;
}
if (entry instanceof Primitive) {
final Primitive p = (Primitive) entry;
writePrimitive(p.getType(), writer, p);
return;
}
if (entry instanceof PrimitiveList) {
final PrimitiveList pl = (PrimitiveList) entry;
writer.beginArray();
for (final DynamoDBEntry e : pl.getEntries()) {
writePrimitive(pl.getType(), writer, e);
}
writer.endArray();
return;
}
if (entry instanceof DynamoDBList) {
final DynamoDBList pl = (DynamoDBList) entry;
writer.beginArray();
for (final DynamoDBEntry e : pl.getEntries()) {
writeJson(e, writer);
}
writer.endArray();
return;
}
if (entry instanceof DynamoDBBool) {
writer.value(((DynamoDBBool) entry).asBoolean());
return;
}
if (entry instanceof DynamoDBNull) {
writer.nullValue();
return;
}
throw new JsonParseException("unable to convert to json " + entry);
}
Aggregations