public class ScriptedTransformer extends java.lang.Object implements Transformer, java.io.Serializable
Transformer that uses a ScriptEngine compatible script to
transform data.
The provided script has access to the key and value that are candidates for
transformation. The key is available via a variable named key and
the value is available via a variable named value.
The last line of the script determines the return value of the
transformation. If an Object or Map-like value is returned from the script,
the same is returned from the transform(String, Object) function.
Otherwise, scalar values are assumed to be transformations to the original
value. In those instances, the original key is preserved and the original
value is replaced by the script's returned value.
| Modifier and Type | Class and Description |
|---|---|
static class |
ScriptedTransformer.Builder
Base
ScriptedTransformer.Builder for ScriptedTransformers. |
static class |
ScriptedTransformer.JavascriptTransformerBuilder
A
ScriptedTransformer.Builder for Javascript based ScriptedTransformers. |
| Modifier and Type | Method and Description |
|---|---|
java.util.Map<java.lang.String,java.lang.Object> |
transform(java.lang.String key,
java.lang.Object value)
Potentially transform the provided
key and value pair. |
static ScriptedTransformer.Builder |
usingJavascript()
Return a builder that will create a
ScriptedTransformer that uses
a javascript interpreter. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitdeserialize, serialize, transform, transformpublic static ScriptedTransformer.Builder usingJavascript()
ScriptedTransformer that uses
a javascript interpreter.public java.util.Map<java.lang.String,java.lang.Object> transform(java.lang.String key,
java.lang.Object value)
Transformerkey and value pair.
There are four possible transformation scenarios:
null. In the other scenarios,
this method returns a Map which contains the data that will
replace the original key and value. So, if the
input parameters are part of a larger data map, the caller should
merge the data
from this map with the source data.
Even though the inputs to this method are simple, a Map is
returned to allow for complex transformations. For example,
Transformation#to(Object, Object) utility.
transform in interface Transformerkey - the raw key to potentially transformvalue - the raw value to potentially transform