Forum Discussion

chutchison's avatar
chutchison
New Contributor
8 years ago

Output Date Type in Custom Snap

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

  • tstack's avatar
    tstack
    Former Employee

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

  • chutchison's avatar
    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.

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

    • tstack's avatar
      tstack
      Former Employee

      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.