cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with Arrays in Downstream Mappers after a Custom Snap Transformation

cclaudio
New Contributor II

We built a custom snap that performs a transformation. You will notice in the output of the custom snap in the screenshot below that “medicalEnrollment” is a json array.

image

In a downstream mapper, we attempted a transformation on this array. We have tried (1) using the sl.ensureArray() method and (2) another downstream mapper performing a transformation in the array. However, we notice that in both the #1 and #2 attempts the mappers do not detect the array, thus causing issues with the transformation.

Below is a snippet of the preview of what we expect vs actual preview.

image

We also notice that chaining a Json Formatter and a Json Parser right after the custom snap does indeed makes the mappers work correctly. Pattern shown below:

image

So my question is, is there something hidden in the JSON parser snap that allows strong typing of the array that we are missing? Anything in between?

@robin , Tagging you since I was told you might be able to help out. Thanks!

1 ACCEPTED SOLUTION

Thanks. I installed the binary snap pack and set a breakpoint in the Mapper to see the Java types used in the input, which is the output of your snap. I can see that medicalEnrollment is still a HashSet, not an ArrayList:

Screen Shot 2021-09-09 at 4.43.41 PM

I haven’t studied your source code but I can see that you’re still using HashSet in a lot of places. Don’t use that type anywhere in your Document data. It’s not compatible with any of the JSON types. Use ArrayList everywhere you need an array.

View solution in original post

20 REPLIES 20

When I try to execute either of those pipelines the first snap fails. I think it needs an account.

cclaudio
New Contributor II

@ptaylor Apologies for the incomplete copy. I uploaded the dummy file to the folder and linked it.

Would you be willing to share the binary snap pack for your custom snaps so I can run this on my local development plex and see what’s going on? If so: ptaylor@snaplogic.com

cclaudio
New Contributor II

@ptaylor Will do!

Thanks. I installed the binary snap pack and set a breakpoint in the Mapper to see the Java types used in the input, which is the output of your snap. I can see that medicalEnrollment is still a HashSet, not an ArrayList:

Screen Shot 2021-09-09 at 4.43.41 PM

I haven’t studied your source code but I can see that you’re still using HashSet in a lot of places. Don’t use that type anywhere in your Document data. It’s not compatible with any of the JSON types. Use ArrayList everywhere you need an array.