问题
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®ion=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