class MyCustomRule(
private val sourcePath: String,
private val targetPath: String,
private val multiplier: Int
) : MappingRule {
override fun apply(context: MappingContext, target: Any) {
// Get the source value
val sourceValue = context.getValueByPath(sourcePath)
// Apply your custom logic
val targetValue = when (sourceValue) {
is Number -> sourceValue.toInt() * multiplier
else -> sourceValue
}
// Set the target value
if (target is DataNode.ObjectNode && targetValue != null) {
SimpleMapping.setValueInDataNode(target, targetPath, targetValue)
}
}
}