in common/src/main/java/org/apache/rocketmq/eventbridge/tools/transform/UpdateFieldTransform.java [46:68]
public Data process(Data inputData) throws EventBridgeException {
Map<String, Object> dataMap = new Gson().fromJson(inputData.toString(),
new TypeToken<Map<String, Object>>() {
}.getType());
for (Variable v : fieldList) {
String[] dataList = v.getName()
.split("\\.");
Map<String, Object> tempMap = dataMap;
for (int i = 1; i < dataList.length - 1; i++) {
Object temp = tempMap.get(dataList[i]);
if (!(temp instanceof Map)) {
throw new EventBridgeException(TransformErrorCode.InvalidConfig);
}
tempMap = (Map<String, Object>) temp;
}
if (tempMap.get(dataList[dataList.length - 1]) == null) {
throw new EventBridgeException(TransformErrorCode.InvalidConfig);
}
tempMap.put(dataList[dataList.length - 1], ((JsonPrimitive) v.getValue()).getAsString());
}
String jsonString = JSONObject.toJSONString(dataMap);
return new StringData(jsonString);
}