Last active
February 23, 2016 18:23
-
-
Save ricston-git/9803872 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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