2
votes

I have a table, in that I have a secondary index. My secondary index uses DynamoDB marshalling.

How do I query the table on this GSI? The addRangeKeyCondition, supports only withS, and withN methods. How do I query it with my object? This is how I query it if the Range key is a string:

DynamoDBQueryExpression<RequestPerOfferItem> queryExpr = new DynamoDBQueryExpression<>();
queryExpr.withHashKeyValues(item).withRangeKeyCondition( "KeyName",
              new Condition().withAttributeValueList(new AttributeValue().withS(val)).withComparisonOperator(
                      ComparisonOperator.EQ));

But I cannot do this, as my range key uses a marshaller. How do I query my GSI using this range key?

2

2 Answers

1
votes

You can use the marshaller yourself to get the String representation of the object:

public static class YourObjectMarshaller implements DynamoDBMarshaller<YourObject>
{
   public static final YourObjectMarshaller instance = new YourObjectMarshaller();
...
}

Then you can use it yourself as YourObjectMarshaller.instance.marshall(obj) and pass it as String withS.

0
votes

If you are using the DynamoDBMapper, you can use the @DynamoDBMarshalling annotation and specify the DynamoDBMarshaller to use for your object.

@DynamoDBMarshalling(YourObjectMarshaller.class)
public YourObject getYourObject() {
    ....
}