title: Java DynamoDB Validation exception required "key not given" when exists in JSON
body: <p>Running into exception while running dynamoDB <code>.putItem()</code>.</p>
  
  <p>Table definition:</p>
  
  <pre><code>{
    "AttributeDefinitions": [
      {
        "AttributeName": "storage_CACHE_KEY",
        "AttributeType": "S"
      }
    ],
    "TableName": "my-table",
    "KeySchema": [
      {
        "AttributeName": "storage_CACHE_KEY",
        "KeyType": "HASH"
      }
    ],
    "TableStatus": "ACTIVE",
    "CreationDateTime": "2017-11-01T05:01:18.883Z",
    "ProvisionedThroughput": {
      "LastIncreaseDateTime": "1970-01-01T00:00:00.000Z",
      "LastDecreaseDateTime": "1970-01-01T00:00:00.000Z",
      "NumberOfDecreasesToday": 0,
      "ReadCapacityUnits": 3,
      "WriteCapacityUnits": 3
    },
    "TableSizeBytes": 199,
    "ItemCount": 1,
    "TableArn": "arn:aws:dynamodb:ddblocal:000000000000:table/my-table"
  } 
  </code></pre>
  
  <p>Additionally value I'm attempting to put when serialized into JSON appears like so:</p>
  
  <pre><code>{
    "storage_CACHE_KEY" : "storage_cache_key_value",
    "some_other_fields" : [""]
  }
  </code></pre>
  
  <p>I still can't figure out why the below errors are occurring:</p>
  
  <pre><code>com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException: One of the required keys was not given a value (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID:
  </code></pre>
  
  <p>Update: How .putItem is being used</p>
  
  <pre><code>public &lt;T&gt; PutItemResult put(String key, T value, Optional&lt;Long&gt; expires) throws JsonProcessingException {
      PutItemRequest req = (new PutItemRequest()).withTableName(this.tableName).withItem(this.keyValuePair(key, value, expires));
      return this.db.putItem(req);
  }
  private Map&lt;String, AttributeValue&gt; buildKey(String value) {
      Map&lt;String, AttributeValue&gt; key = new HashMap();
      key.put("name", new AttributeValue(value));
      return key;
  }
  
  private &lt;T&gt; Map&lt;String, AttributeValue&gt; keyValuePair(String key, T value, Optional&lt;Long&gt; expires) throws JsonProcessingException {
      Map&lt;String, AttributeValue&gt; item = this.buildKey(key);
      item.put("json", new AttributeValue(this.mapper.writeValueAsString(value)));
      if (expires.isPresent()) {
          item.put(this.ttlKey, (new AttributeValue()).withN(((Long)expires.get()).toString()));
      }
  
      return item;
  }
  </code></pre>
  
  <p>I have stepped over this code and have seen that <code>T value</code> is JSON in precisely the format I have posted above.</p>
  
  <p>Update: putItem succeeded when I changed the map entry from <code>name</code> to <code>storage_CACHE_KEY</code> but now read fails to marshal back to my object. The json stored in my local dynamodb for the entry is:</p>
  
  <pre><code>{
    "storage_CACHE_KEY": "4728264794434232301",
    "json": "{\"storage_CACHE_KEY\":\"23232432472826479401\", \"otherFields\": \"example\"}"
  }
  </code></pre>
  
  <p>(0 known properties: ])
  Unrecognized field "present" (class java.util.Optional), not marked as ignorable</p>