要在下面的类中将Map的属性归类,我想使用DynamoDBMapper从Dyanmodb中进行保存和读取。
Map<String, Map<String, Transition>> twf;
public class Transition {
public String fst;
public Permission pm;
public List<Action> ac;
}
public class Action {
private String mdl;
private String dsc;
private String nm;
// email address or any other data
private Map<String, String> data;
}
我尝试将DynamoDBTypeConverted转换为String,这导致json字符串已“转义为\”,并且在dyanmodb中不可读。我想存储为json
我实现了Dyanmodb支持Map的理解,但是仍然出现错误: 异常处理消息:不支持;需要@DynamoDBTyped或@DynamoDBTypeConverted
public class TimeSheetWorkFlowConverter implements
DynamoDBTypeConverter<Map<String, Object>, Map<String, Map<String, Transition>>> {
@Override
public Map convert(Map<String, Map<String, Transition>> object) {
// Map obj = mapper.readValue(object, Map.class);
String newJson = null;
Map objectJson = null;
try {
newJson = mapper.writeValueAsString(object);
objectJson = mapper.readValue(newJson, Map.class);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return objectJson;
}
@SuppressWarnings("unchecked")
@Override
public Map<String, Map<String, Transition>> unconvert(Map<String, Object> object) {
Map<String, Map<String, Transition>> wf = new HashMap<>();
if (object != null && !object.isEmpty())
for (Entry<String, Object> entry : object.entrySet()) {
String key = entry.getKey();
Map<String, Transition> value = mapTransition(entry.getValue());
wf.put(key, value);
}
return wf;
}