How to put a map as attribute value in DynamoDb using apache camel?

空扰寡人 提交于 2020-08-09 09:24:20

问题


I want to put a map like so "M": {"Name": {"S": "Joe"}, "Age": {"N": "35"}} using the PutItem opearation of apache camel. The code would be something like this ->

.post("dynamodb-put-item")
    .route()
    .process(new Processor(){
        @Override
        public void process(Exchange exchange) throws Exception {
            Map<String, AttributeValue> key = new HashMap();
            key.put("M", AttributeValue.builder().m(//Something needs to be added here).build());
            exchange.getIn().setHeader(Ddb2Constants.ITEM, key);
            exchange.getIn().setHeader(Ddb2Constants.RETURN_VALUES, "ALL_OLD");

        }
        
    })
    .toD("aws2-ddb://user?accessKey=insert&secretKey=insert&region=us-east-1&operation=PutItem")
    .endRest();

{"Name": {"S": "Joe"} and "Age": {"N": "35"}} are individually a Map<String, Attribute value>. For this example I can manually hard code it by creating one more map for {"Name": {"S": "Joe"} and "Age": {"N": "35"}}. But I am looking for a general solution because a map can be of type string, boolean , map, list etc. How to make a general thing which will handle all the possible cases of a map?

来源:https://stackoverflow.com/questions/63136841/how-to-put-a-map-as-attribute-value-in-dynamodb-using-apache-camel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!