cancel
Showing results for 
Search instead for 
Did you mean: 

Output Date Type in Custom Snap

chutchison
New Contributor

Is there a way to output a SnapLogic “Date” type (as discussed here: https://docs-snaplogic.atlassian.net/wiki/spaces/SD/pages/1439344/Date+Functions+and+Properties) as a column in a document being written to a snap’s output view?

I would like consumers of the snap to be able to format the dates using toLocaleDateString() / toLocaleDateTimeString() / toLocaleTimeString() without having to Date.parse(…) a string in a mapper first.

I have tried writing Java’s LocalDate, LocalDateTime, and ZonedDateTime as well as Joda-Time’s DateTime objects to the view with no success. Additionally, after any of those date objects are written to the view, none of the remaining columns are written to the output view.

3 REPLIES 3

tstack
Former Employee

Can you post a code snippet of what you tried with the Joda DateTime object that didn’t work?

chutchison
New Contributor

Sure! Here’s a repository full of examples: GitHub - chutch1122/snap-date-issue

Specifically, with Joda’s DateTime object: snap-date-issue/JodaDateTimeSnap.java at master · chutch1122/snap-date-issue · GitHub

    Map<String, Object> row = new LinkedHashMap<>();

    row.put("firstName", "Bobby");
    row.put("lastName", "Tables");
    row.put("dateOfBirth", new DateTime(1990, 12, 25, 1, 30));
    row.put("email", "bobby@tables.com");
    row.put("yearsExperience", 5);

    Document document = documentUtility.newDocument(row);
    outputViews.write(document);

This is what happens when I run a pipeline with that snap. SnapLogic Joda DateTime Issue

Note that none of the properties after dateOfBirth are present (email, yearsExperience) and SnapLogic doesn’t let me format the date.

It looks like a class-loading issue, the class used in your pack is loaded separately from the one in the platform, so the platform doesn’t know how to deal with it. When I unzip the build of the pack I see the joda jar in there, so that is probably why it’s being loaded in and used. You can try adding joda to the pom in the ‘provided’ scope.