Dynamodbmapping异常:取消转换属性List <string>属性“

时间:2019-01-10 07:12:41

标签: java amazon-web-services

当我尝试使用Java API通过dynamoDB提取项目时,出现诸如“ dynamodbmapping异常:未转换属性List属性”之类的gettint错误。我的pojo包含字符串和字符串变量列表。

@DynamoDBTable(tableName =“ USERS_PROFILE”) 公共类UsersProfile {

@DynamoDBHashKey(attributeName="USERID")
private String userId;
@DynamoDBAttribute(attributeName="FIRSTNAME")
private String firstName;
@DynamoDBAttribute(attributeName="LASTNAME")
private String lastName;
@DynamoDBAttribute(attributeName="EMAIL")
private String email;
//@DynamoDBTypeConvertedEnum
@DynamoDBAttribute(attributeName="APPLIST")
private List<String> appList;
//private String appList;


public String getUserId() {
    return userId;
}
public void setUserId(String userId) {
    this.userId = userId;
}
public String getFirstName() {
    return firstName;
}
public void setFirstName(String firstName) {
    this.firstName = firstName;
}
public String getLastName() {
    return lastName;
}
public void setLastName(String lastName) {
    this.lastName = lastName;
}
public String getEmail() {
    return email;
}
public void setEmail(String email) {
    this.email = email;
}
public List getAppList() {
    return appList;
}
public void setAppList(List appList) {
    this.appList = appList;
}
/*public Map<String, String> getAppList() {
    return appList;
}
public void setAppList(Map<String, String> appList) {
    this.appList = appList;
}

* /     / *公共字符串getAppList(){         返回appList; enter code here     }     public void setAppList(String appList){         this.appList = appList;     }     * /     }

公共列表getAppList(String userId){         尝试{

        awsCredentials = AWSAuthenticationUtil.getAWSCredentials();
        amazonDynamoDBClient = DynamoDBUtil.getAmazonDynamoDBClient(awsCredentials);

        DynamoDBMapper dynamoDBMapper = new DynamoDBMapper(amazonDynamoDBClient);

        Map<String, AttributeValue> attributeValues = new HashMap<String, AttributeValue>();
        attributeValues.put(":v1", new AttributeValue().withS(userId));



        DynamoDBQueryExpression<UsersProfile> queryExpression = new DynamoDBQueryExpression<UsersProfile>()
                   .withConsistentRead(false)
                   .withKeyConditionExpression("USERID = :v1")
                   .withExpressionAttributeValues(attributeValues);


        List<UsersProfile> appList =  dynamoDBMapper.query(UsersProfile.class, queryExpression);

        if(appList.size()>0){
            return (List<UsersProfile>) appList.get(0);
        } else {
                return null;
        }


    } catch (AmazonServiceException ase) {
        throw new RuntimeException("Internal Server Error");
    } catch (AmazonClientException ace){
        throw new RuntimeException("Internal Server Error");
    } catch (Exception e){
        throw new RuntimeException(e.getMessage());
    } finally {
        amazonDynamoDBClient = null;
        awsCredentials = null;
    }

}

基于“用户ID”作为输入参数发送,我们可以在对象列表中获取项目。

0 个答案:

没有答案