Last active
October 12, 2018 10:45
-
-
Save webster92/3bad59abd4b58d8d671addfa5dab9708 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
%dw 1.0 | |
%output application/java | |
%function getCsvFile(csvFile) | |
readUrl("classPath://" ++ csvFile, "application/csv") | |
%function toType(value, type) | |
null when value == '' otherwise ( | |
value as :number when type == 'number' otherwise | |
value as :date when type == 'number' otherwise | |
value as :time when type == 'time' otherwise | |
value as :datetime when type == 'datetime' otherwise | |
value as :boolean when type == 'boolean' otherwise | |
(value when value != '<empty_string>' otherwise '') | |
) | |
%function csvToJava(csvFile) | |
using(csv = getCsvFile(csvFile))( | |
(csv filter $$ > 0) map ((obj, position) -> | |
obj mapObject ( | |
'$$': toType($, csv[0][$$]) | |
) | |
) | |
) | |
--- | |
{ | |
csvToJava: csvToJava | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment