Get Ouptviews for a custom snap

Hi Experts,

I am developing a custom snap which connects to a Mapper. In process(Document document, String s), I get data from the Mapper and then I convert this map data to JSON object by:
Map<String, Object> inputDataFromMapper = document.get(Map.class);.
JSONObject inputDataJsonObj = new JSONObject(inputDataFromMapper);

And now I want to show this JSON object as the outputview of my custom snap by:
Document data = documentUtility.newDocument(documentUtility.newDocument(inputDataJsonObj), document);
outputViews.write(documentUtility.newDocumentFor(document, data));

However, I am getting this error in my custom snap after validating the pipeline.

Please share your ideas on how I can solve this error!

Hi JiWon,

There’s no need to use the JSONObject class or anything similar to convert the map data to JSON. In the Snap API, the data structures associated with input and output documents aren’t JSON; they are just Java objects like Map, List, and primitives (String, Integer, etc). These data structures can be easily mapped to JSON but you don’t need to use any sort of JSON-specific API to read or write them.

Try something like this instead:

Document outputDoc = documentUtility.newDocumentFor(document, inputDataFromMapper);
1 Like

Hi ptaylor,

Thanks for being a big help! It works