I have a 3 functions in Dataweave transform message component and I would like to reuse these functions in 4 other transform message components.
Is there a way I can centralise the 3 functions and reference them in the 4 other transform message components without copying and pasting the function into every transform message I want to use it with?
I am using Anypoint Studio 6.1 and Mule 3.8.1.
The 3 functions in Dataweave that I would like to access globally in my project are:
%function acceptable(value) (
value match {
:null -> false,
a is :array -> a != [{}],
o is :object -> o != {},
s is :string -> s != "",
default -> true
}
)
%function filterKeyValue(key, value) (
{(key): value} when acceptable(value) otherwise {}
)
%function removeFields(x)
x match {
a is :array -> a map removeFields($),
o is :object -> o mapObject
(filterKeyValue($$, removeFields($))),
default -> $
}
These functions were taken from a Stackoverflow post around removing empty fields and I am getting this error when I try to deploy the application:
INFO 2017-02-17 19:31:37,190 [main] org.mule.config.spring.MuleArtifactContext: Closing org.mule.config.spring.MuleArtifactContext@70b2fa10: startup date [Fri Feb 17 19:31:30 GMT 2017]; root of context hierarchy
ERROR 2017-02-17 19:31:37,478 [main] org.mule.module.launcher.application.DefaultMuleApplication: null
org.mule.mvel2.CompileException: [Error: unknown class or illegal statement: org.mule.mvel2.ParserContext@515940af]
[Near : {... value match { ....}]
^
[Line: 3, Column: 20]
at org.mule.mvel2.compiler.AbstractParser.procTypedNode(AbstractParser.java:1476) ~[mule-mvel2-2.1.9-MULE-010.jar:?]
Thanks