content: package com.amazon.asksdk.scorekeeper.storage;
  
  import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute;
  import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey;
  import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMarshaller;
  import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMarshalling;
  import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable;
  import com.fasterxml.jackson.core.JsonProcessingException;
  import com.fasterxml.jackson.core.type.TypeReference;
  import com.fasterxml.jackson.databind.ObjectMapper;
  
  /**
   * Model representing an item of the ScoreKeeperUserData table in DynamoDB for the ScoreKeeper
   * skill.
   */
  @DynamoDBTable(tableName = "ScoreKeeperUserData")
  public class ScoreKeeperUserDataItem {
      private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
  
      private String customerId;
  
      private ScoreKeeperGameData gameData;
  
      @DynamoDBHashKey(attributeName = "CustomerId")
      public String getCustomerId() {
          return customerId;
      }
  
      public void setCustomerId(String customerId) {
          this.customerId = customerId;
      }
  
      @DynamoDBAttribute(attributeName = "Data")
      @DynamoDBMarshalling(marshallerClass = ScoreKeeperGameDataMarshaller.class)
      public ScoreKeeperGameData getGameData() {
          return gameData;
      }
  
      public void setGameData(ScoreKeeperGameData gameData) {
          this.gameData = gameData;
      }
  
      /**
       * A {@link DynamoDBMarshaller} that provides marshalling and unmarshalling logic for
       * {@link ScoreKeeperGameData} values so that they can be persisted in the database as String.
       */
      public static class ScoreKeeperGameDataMarshaller implements
              DynamoDBMarshaller<ScoreKeeperGameData> {
  
          @Override
          public String marshall(ScoreKeeperGameData gameData) {
              try {
                  return OBJECT_MAPPER.writeValueAsString(gameData);
              } catch (JsonProcessingException e) {
                  throw new IllegalStateException("Unable to marshall game data", e);
              }
          }
  
          @Override
          public ScoreKeeperGameData unmarshall(Class<ScoreKeeperGameData> clazz, String value) {
              try {
                  return OBJECT_MAPPER.readValue(value, new TypeReference<ScoreKeeperGameData>() {
                  });
              } catch (Exception e) {
                  throw new IllegalStateException("Unable to unmarshall game data value", e);
              }
          }
      }
  }
  