Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@webster92
Last active October 12, 2018 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webster92/3bad59abd4b58d8d671addfa5dab9708 to your computer and use it in GitHub Desktop.
Save webster92/3bad59abd4b58d8d671addfa5dab9708 to your computer and use it in GitHub Desktop.
%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