List of usage examples for com.amazonaws.services.dynamodbv2.document Item getRawMap
@SuppressWarnings("unchecked") public Map<String, Object> getRawMap(String attrName)
Object's; or null if the attribute either doesn't exist or the attribute value is null. From source file:com.github.fge.jsonpatch.JsonPatchToXSpecRemove.java
License:LGPL
@Test public void test_remove_nestedPath() throws Exception { // setup/* w w w.ja v a 2 s. c o m*/ table.putItem(Item.fromMap(ImmutableMap.<String, Object>builder().put(KEY_ATTRIBUTE_NAME, VALUE) .put("a", ImmutableMap.of("a", 2, "b", true)).build())); // setup String patchExpression = "[ { \"op\": \"remove\", \"path\": \"/a/a\" } ]"; JsonNode jsonNode = JsonLoader.fromString(patchExpression); JsonPatch jsonPatch = JsonPatch.fromJson(jsonNode); // exercise ExpressionSpecBuilder actual = jsonPatch.get(); UpdateItemExpressionSpec actualSpec = actual.buildForUpdate(); table.updateItem(KEY_ATTRIBUTE_NAME, VALUE, actualSpec); // verify Item item = table.getItem(PK); Assert.assertTrue(item.hasAttribute("key")); Assert.assertEquals(item.getString("key"), "keyValue"); Assert.assertTrue(item.hasAttribute("a")); Assert.assertTrue(item.getRawMap("a").containsKey("b")); Assert.assertEquals(item.getRawMap("a").get("b"), true); Assert.assertFalse(item.getRawMap("a").containsKey("a")); }
From source file:com.github.fge.jsonpatch.JsonPatchToXSpecReplace.java
License:LGPL
@Test public void test_replace_existingNestedPath_string() throws Exception { // setup/*from w w w .j a v a2 s . c o m*/ table.putItem(Item.fromMap(ImmutableMap.<String, Object>builder().put(KEY_ATTRIBUTE_NAME, VALUE) .put("a", ImmutableMap.of("a", 2L, "b", true)).build())); String patchExpression = "[ { \"op\": \"replace\", \"path\": \"/a/b\", \"value\": \"bar\" } ]"; JsonNode jsonNode = JsonLoader.fromString(patchExpression); JsonPatch jsonPatch = JsonPatch.fromJson(jsonNode); // exercise ExpressionSpecBuilder builder = jsonPatch.get(); UpdateItemExpressionSpec spec = builder.buildForUpdate(); table.updateItem(KEY_ATTRIBUTE_NAME, VALUE, spec); // verify Item item = table.getItem(PK); Assert.assertTrue(item.hasAttribute("key")); Assert.assertEquals(item.getString("key"), "keyValue"); Assert.assertTrue(item.hasAttribute("a")); Assert.assertTrue(item.getRawMap("a").containsKey("a")); Assert.assertEquals(((BigDecimal) item.getRawMap("a").get("a")).longValue(), 2L); Assert.assertTrue(item.getRawMap("a").containsKey("b")); Assert.assertEquals(item.getRawMap("a").get("b"), "bar"); }
From source file:com.github.fge.jsonpatch.JsonPatchToXSpecReplace.java
License:LGPL
@Test public void test_replace_singlePath_object() throws Exception { table.putItem(Item.fromMap(/*from w w w.j av a2s . co m*/ ImmutableMap.<String, Object>builder().put(KEY_ATTRIBUTE_NAME, VALUE).put("a", 1L).build())); // setup String patchExpression = "[ { \"op\": \"replace\", \"path\": \"/a\", \"value\": {\"b\": \"c\", \"d\": 1} } ]"; JsonNode jsonNode = JsonLoader.fromString(patchExpression); JsonPatch jsonPatch = JsonPatch.fromJson(jsonNode); // exercise ExpressionSpecBuilder builder = jsonPatch.get(); UpdateItemExpressionSpec spec = builder.buildForUpdate(); table.updateItem(KEY_ATTRIBUTE_NAME, VALUE, spec); // verify Item item = table.getItem(PK); Assert.assertTrue(item.hasAttribute("key")); Assert.assertEquals(item.getString("key"), "keyValue"); Assert.assertTrue(item.hasAttribute("a")); Assert.assertTrue(item.getRawMap("a").containsKey("b")); Assert.assertEquals(item.getRawMap("a").get("b"), "c"); Assert.assertTrue(item.getRawMap("a").containsKey("d")); Assert.assertEquals(((BigDecimal) item.getRawMap("a").get("d")).longValue(), 1L); }