1

I am working in Android app that sync data in DynamoDB

I need to insert attribute List<Map<String, Object>>

here is my DynamoDB table structure

public class AmznDynamoDeviceDB {
    private String identityID;    
    private String deviceName;
    private List<Map<String, Object>> channels;

    @DynamoDBHashKey(attributeName = "identityID")
    public String getIdentityId(){
        return this.identityID;
    }
    public void setIdentityId(String identityID){
        this.identityID = identityID;
    }

    @DynamoDBAttribute(attributeName = "deviceName")
    public String getDeviceName(){
        return this.deviceName;
    }
    public void setDeviceName(String deviceName){
        this.deviceName = deviceName;
    }

    @DynamoDBAttribute(attributeName = "channels")
    public List<Map<String, Object>> getChannels(){
        return this.channels;
    }
    public void setChannels(List<Map<String, Object>> channels){
        this.channels = channels;
    }    
}

and i am getting the following error when insert in DynamoDB

W/System.err: com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBMappingException: Cannot marshall type class java.lang.Object without a custom marshaler or @DynamoDBDocument annotation.

Can i insert java.lang.Object in Map element in DynamoDB.

Note : If i use @DynamoDBMarshalling the stores data as String i need to insert as List<Map<String, Object>>

Thanks in advance.

2 Answers 2

1

If you would like to keep the channel attribute as List<Map<String, Object>>, the simple answer is that you can't save the values as List of Map objects. The only solution available is to convert the data as String and store in DynamoDB.

Couple of options to convert to String or JSON:-

1) @DynamoDBTypeConvertedJson - This annotation can be used to convert the data into JSON and store it as String attribute in DynamoDB

@DynamoDBMarshalling - is deprecated

2) Write a custom converter. Again, this will save the data as String in DynamoDB.

DynamoDBTypeConverted

Note:-

Though DynamoDB supports Document data types such as List and Map, it will be impossible to query the data if you have Map inside List. The DynamoDB API doesn't support filtering the data for this data model.

If you need to support any use case querying/updating the channels attribute, I would strongly recommend to rethink about the data model to flatten the data structure.

Another drawback is that index can't be created on Document data types (List and Map).

Sign up to request clarification or add additional context in comments.

Comments

0

I am not sure what you are looking for here. Whenever any object goes on network or saved into database; it is saved as String.. Now how to achieve this is to make that object serializable.. Make sure that your object ( inside List ) implements Serializable.

You should not be worried if it is saved as String in DB ( because that will anyway be because that is another system and not JVM which can hold java object ) ; what should matter is that when you ask for this object ; dynamoDB automatically converts this object to a List which is what you need.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.