DyanmoDb存储值1而不是布尔值true [英] DyanmoDb is storing value 1 instead of boolean value true

查看:144
本文介绍了DyanmoDb存储值1而不是布尔值true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个方法,该方法只是为特定记录存储标志值true.我的标志属性已定义为Boolean,在我的DynamoDB数据库中其值为true/false. 在运行此方法时,将以某种方式代替存储true值,而是将flag属性插入一个新列作为number数据类型,并写入值1而不是true.在调试时,我可以看到它读取的值为"true",但是在写我的猜测时,它需要1表示true,0表示false,因此编写1.

I have a method which is simply storing flag value true for a particular record. My flag attribute has been defined as Boolean which has value true/false in my DynamoDB database. While running this method, somehow instead of storing true value, it is inserting a new column for the flag attribute as number datatype and writing value 1 instead of true. While debugging I can see it is reading the value as "true" but while writing my guess is it is taking 1 for true and 0 for false, and hence writing 1.

public static ArrayList<UserWishListBuks> removeNotification(int Statusid) {
    AmazonDynamoDBClient ddb = NavigationDrawerActivity.clientManager
            .ddb();
    DynamoDBMapper mapper = new DynamoDBMapper(ddb);
    DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();
    Boolean value = true;
    try{
        PaginatedScanList<UserWishListBuks> result = mapper.scan(
                UserWishListBuks.class, scanExpression);
        for (UserWishListBuks bre : result) {
            if( (bre.getBOOK_STATUS_ID()==(Statusid))   )
            {
                bre.setNOTIFICATION_FLAG(true);
                mapper.save(bre);
            }
        }
    }catch (AmazonServiceException ex) {
        NavigationDrawerActivity.clientManager
                .wipeCredentialsOnAuthError(ex);
    }
    return null;
   }

推荐答案

这是预料之中的,请查看dynamodb的数据类型文档:

That's expected, have a look at the datatypes docs for dynamodb: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBMapper.DataTypes.html

Java的Boolean类型将以数字类型存储在dynamodb,0或1中. 或者,您可以使用@DynamoDBNativeBooleanType将Java Boolean映射到DynamoDB BOOL数据类型

The Java type of Boolean will be stored as a number type in dynamodb, 0 or 1. Alternatively, you can use @DynamoDBNativeBooleanType to map a Java Boolean to the DynamoDB BOOL data type

这篇关于DyanmoDb存储值1而不是布尔值true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆