Search in sources :

Example 1 with DynamoDBNull

use of com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.DynamoDBNull 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);
}
Also used : DynamoDBEntry(com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.DynamoDBEntry) Primitive(com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.Primitive) JsonPrimitive(com.google.gson.JsonPrimitive) PrimitiveList(com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.PrimitiveList) DynamoDBBool(com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.DynamoDBBool) DynamoDBNull(com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.DynamoDBNull) Document(com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.Document) JsonParseException(com.google.gson.JsonParseException) DynamoDBList(com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.DynamoDBList)

Aggregations

Document (com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.Document)1 DynamoDBBool (com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.DynamoDBBool)1 DynamoDBEntry (com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.DynamoDBEntry)1 DynamoDBList (com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.DynamoDBList)1 DynamoDBNull (com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.DynamoDBNull)1 Primitive (com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.Primitive)1 PrimitiveList (com.amazonaws.mobileconnectors.dynamodbv2.document.datatype.PrimitiveList)1 JsonParseException (com.google.gson.JsonParseException)1 JsonPrimitive (com.google.gson.JsonPrimitive)1