derjust / spring-data-dynamodb

This module deals with enhanced support for a data access layer built on AWS DynamoDB.
https://derjust.github.io/spring-data-dynamodb/
Apache License 2.0
403 stars 141 forks source link

Enum Mapping #266

Open gurpiarbassi opened 5 years ago

gurpiarbassi commented 5 years ago

Expected Behavior

Enums are mapped consistently

Actual Behavior

Finding that enums are not mapped when part of a nested DynamoDBDocument.

Steps to Reproduce the Problem

@DynamoDBTable(tableName = "Orders")
public class Order {
  //hash key
 // range key
 // attributes
 @DynamoDBAttribute(attributeName = "OrderData")
    private OrderData orderData;
}

@DynamoDBDocument
public class OrderData {
@DynamoDBAttribute(attributeName = "customer")
    private Customer customer;

 @DynamoDBAttribute(attributeName = "Source")
 @DynamoDBTypeConverted(converter = OrderChannel.OrderChannelEnumConverter.class)
    private OrderChannel source;
}

@DynamoDBDocument
public class Customer {
   @DynamoDBAttribute(attributeName = "customerType")
   @DynamoDBTypeConverted(converter = CustomerType.CustomerTypeConvertor)
    private CustomerType customerType;
}

The source attribute above persists perfectly. However the CustomerType does not. Any enum that is more than 1 level deep in the DynamoDBDocument i.e in sub documents does not get converted into a string. It comes up as type B i.e. byte buffer.

The custom convertors mentioned above don't do anything clever apart from convert between enum to string and vice versa.

Specifications