4

Is there a way to convert a collection of enums? I've tried the following without success:

@DynamoDBTypeConvertedEnum
@DynamoDBAttribute(attributeName="myEnums")
private Collection<MyEnum> myEnums;
bsferreira
  • 1,189
  • 5
  • 14
  • 27

2 Answers2

4

In order to save it as collection (i.e. set of strings), please use @DynamoDBTyped annotation with SS attribute type.

@DynamoDBTyped(DynamoDBAttributeType.SS)
@DynamoDBAttribute(attributeName = "myEnums")
public Set<MyEnum> getMyEnums() {
    return myEnums;
}
notionquest
  • 37,595
  • 6
  • 111
  • 105
  • I would be interested to know if this method works out. Definitely the best option if it works. I've found problems with Dynamo 'unconverting' Sets correctly before though (without a custom converter). – F_SO_K Dec 20 '17 at 14:35
2

myEnums is a Set of enums, not an enum itself.

DynamoDBTyped

The enum type is only supported by override or custom converter

Because you have a set of enums, you will need to use a customer converter. So remove the @DynamoDBTypeConvertedEnum annotation and use a custom converter. You can see an example I have posted before here. Its a generic Set example but it will work for your enum Set.

EDIT: i.e. use DynamoDBTypeConverted

Vikdor
  • 23,934
  • 10
  • 61
  • 84
F_SO_K
  • 13,640
  • 5
  • 54
  • 83