Skip to content

Instantly share code, notes, and snippets.

@ricston-git
Last active February 23, 2016 18:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ricston-git/9803872 to your computer and use it in GitHub Desktop.
Save ricston-git/9803872 to your computer and use it in GitHub Desktop.
Printed object: [['id3' : 'value3', 'id2' : 'value2', 'id1' : 1], ['id3' : ['id3' : 'value3', 'id2' : 'value2', 'id1' : 'value1'], 'id2' : 'value2', 'id1' : 'value1'], ['id3' : 'value3', 'id2' : 'value2', 'id1' : 'value1']]
org.mule.api.processor.LoggerMessageProcessor: [{id3=value3, id2=value2, id1=1}, {id3={id3=value3, id2=value2, id1=value1}, id2=value2, id1=value1}, {id3=value3, id2=value2, id1=value1}]
def s = printObject(message.payload)
println('Printed object: ' + s)
return payload
String printObject(o)
{
if (o instanceof List) return printList(o)
if (o instanceof Map) return printMap(o)
if ((o instanceof Integer) || (o instanceof Long) || (o instanceof Float) || (o instanceof Double)) return printNumber(o)
return printString(o)
}
String printList(l)
{
def sl = new StringBuilder()
sl << '['
l.each{ i -> sl << printObject(i) +', ' }
sl.delete(sl.length()-2, sl.length())
sl << ']'
return sl
}
String printMap(m)
{
def sm = new StringBuilder()
sm << '['
m.each{ k, v-> sm << printObject(k) +' : '+ printObject(v) +', ' }
sm.delete(sm.length()-2, sm.length())
sm << ']'
return sm
}
String printNumber(n)
{
return n
}
String printString(s)
{
return s == null ? "null" : "'" + s + "'"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment