@Override public void typeCheck(AttributeValue value, Method setter) { if ( value.getM() == null ) { throw new DynamoDBMappingException("Expected M in value " + value + " when invoking " + setter); } }
@Override public Object unmarshall(AttributeValue value) throws ParseException { Map<String, AttributeValue> map = value.getM(); return converter.unconvert(clazz, map); } }
@Override public Object unmarshall(AttributeValue value) throws ParseException { Map<String, AttributeValue> map = value.getM(); Map<String, Object> result = new HashMap<String, Object>(); for (Map.Entry<String, AttributeValue> entry : map.entrySet()) { memberUnmarshaller.typeCheck(entry.getValue(), null); result.put(entry.getKey(), memberUnmarshaller.unmarshall(entry.getValue())); } return result; } }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getS() == null) ? 0 : getS().hashCode()); hashCode = prime * hashCode + ((getN() == null) ? 0 : getN().hashCode()); hashCode = prime * hashCode + ((getB() == null) ? 0 : getB().hashCode()); hashCode = prime * hashCode + ((getSS() == null) ? 0 : getSS().hashCode()); hashCode = prime * hashCode + ((getNS() == null) ? 0 : getNS().hashCode()); hashCode = prime * hashCode + ((getBS() == null) ? 0 : getBS().hashCode()); hashCode = prime * hashCode + ((getM() == null) ? 0 : getM().hashCode()); hashCode = prime * hashCode + ((getL() == null) ? 0 : getL().hashCode()); hashCode = prime * hashCode + ((getNULL() == null) ? 0 : getNULL().hashCode()); hashCode = prime * hashCode + ((getBOOL() == null) ? 0 : getBOOL().hashCode()); return hashCode; }
.withS(entry.getValue().getS()) .withSS(entry.getValue().getSS()) .withM(entry.getValue().getM()) .withL(entry.getValue().getL()) .withNULL(entry.getValue().getNULL())
/** * Marshall the given parameter object. */ public void marshall(AttributeValue attributeValue, ProtocolMarshaller protocolMarshaller) { if (attributeValue == null) { throw new SdkClientException("Invalid argument passed to marshall(...)"); } try { protocolMarshaller.marshall(attributeValue.getS(), S_BINDING); protocolMarshaller.marshall(attributeValue.getN(), N_BINDING); protocolMarshaller.marshall(attributeValue.getB(), B_BINDING); protocolMarshaller.marshall(attributeValue.getSS(), SS_BINDING); protocolMarshaller.marshall(attributeValue.getNS(), NS_BINDING); protocolMarshaller.marshall(attributeValue.getBS(), BS_BINDING); protocolMarshaller.marshall(attributeValue.getM(), M_BINDING); protocolMarshaller.marshall(attributeValue.getL(), L_BINDING); protocolMarshaller.marshall(attributeValue.getNULL(), NULL_BINDING); protocolMarshaller.marshall(attributeValue.getBOOL(), BOOL_BINDING); } catch (Exception e) { throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e); } }
@Override public void typeCheck(AttributeValue value, Method setter) { if (value.getM() == null) { throw new DynamoDBMappingException("Expected M in value " + value + " when invoking " + setter); } }
@Override public Object unmarshall(AttributeValue value) throws ParseException { final Map<String, AttributeValue> map = value.getM(); return converter.unconvert(clazz, map); } }
@Override public Object unmarshall(AttributeValue value) throws ParseException { final Map<String, AttributeValue> map = value.getM(); final Map<String, Object> result = new HashMap<String, Object>(); for (final Map.Entry<String, AttributeValue> entry : map.entrySet()) { memberUnmarshaller.typeCheck(entry.getValue(), null); result.put(entry.getKey(), memberUnmarshaller.unmarshall(entry.getValue())); } return result; } }
private static Document toDynamoDBDocument(final AttributeValue attributeValue) { Document document = null; if (attributeValue.getM() != null) { document = new Document(); final Map<String, AttributeValue> mapAttributes = attributeValue.getM(); for (final Entry<String, AttributeValue> entry : mapAttributes.entrySet()) { document.put(entry.getKey(), attributeValueToDynamoDBEntry(entry.getValue())); } } return document; }
@Override public CompletableFuture<User> getUser(RequestContext context, Object userId) { return CompletableFuture.supplyAsync(() -> { GetItemResult item = dynamoDBClient.getItem("users", ImmutableMap.of( "project", new AttributeValue(context.project), "id", new AttributeValue(userId.toString()) )); Map<String, AttributeValue> attrs = item.getItem().get("properties").getM(); ObjectNode obj = JsonHelper.jsonObject(); for (Entry<String, AttributeValue> entry : attrs.entrySet()) { obj.set(entry.getKey(), getJsonValue(entry.getValue())); } return new User(userId, null, obj); }); }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getS() == null) ? 0 : getS().hashCode()); hashCode = prime * hashCode + ((getN() == null) ? 0 : getN().hashCode()); hashCode = prime * hashCode + ((getB() == null) ? 0 : getB().hashCode()); hashCode = prime * hashCode + ((getSS() == null) ? 0 : getSS().hashCode()); hashCode = prime * hashCode + ((getNS() == null) ? 0 : getNS().hashCode()); hashCode = prime * hashCode + ((getBS() == null) ? 0 : getBS().hashCode()); hashCode = prime * hashCode + ((getM() == null) ? 0 : getM().hashCode()); hashCode = prime * hashCode + ((getL() == null) ? 0 : getL().hashCode()); hashCode = prime * hashCode + ((getNULL() == null) ? 0 : getNULL().hashCode()); hashCode = prime * hashCode + ((getBOOL() == null) ? 0 : getBOOL().hashCode()); return hashCode; }
private FieldType getType(AttributeValue value) { if (value.isBOOL()) { return FieldType.BOOLEAN; } else if (value.getS() != null) { return STRING; } else if (value.getN() != null) { return FieldType.DOUBLE; } else if (value.getL() != null) { return FieldType.ARRAY_STRING; } else if (value.getM() != null) { return FieldType.MAP_STRING; } else { if (!value.isNULL()) { throw new IllegalStateException(); } else { return STRING; } } }
@Test public void testMap() { assertEquals(new HashMap<String, AttributeValue>() { { put("a", new AttributeValue("b")); put("c", new AttributeValue("d")); put("e", new AttributeValue("f")); } }, convert("getMap", new HashMap<String, String>() { { put("a", "b"); put("c", "d"); put("e", "f"); } }).getM()); assertEquals(Collections.singletonMap("a", new AttributeValue().withNULL(true)), convert("getMap", Collections.<String, String> singletonMap("a", null)).getM()); }
@Test public void testMap() { assertEquals(new HashMap<String, AttributeValue>() { { put("a", new AttributeValue("b")); put("c", new AttributeValue("d")); put("e", new AttributeValue("f")); } }, convert("getMap", new HashMap<String, String>() { { put("a", "b"); put("c", "d"); put("e", "f"); } }).getM()); assertEquals(Collections.singletonMap("a", new AttributeValue().withNULL(true)), convert("getMap", Collections.<String, String> singletonMap("a", null)).getM()); }
@Test public void testObject() { assertEquals(new HashMap<String, AttributeValue>() { { put("name", new AttributeValue("name")); put("value", new AttributeValue().withN("123")); } }, convert("getObject", new SubClass()).getM()); }
@Test public void testObject() { assertEquals(new HashMap<String, AttributeValue>() { { put("name", new AttributeValue("name")); put("value", new AttributeValue().withN("123")); } }, convert("getObject", new SubClass()).getM()); }