cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Snap- Get response in json format

DharaSP
New Contributor

I am developing a custom SNAP that makes HTTP request and gets JSON response in return. The response is array of objects. In order to right it to document , currently it only shows up if I convert the response to string in following manner:

Map<String, Object> data = new LinkedHashMap<>();
data.put(“Response”, response);
outputViews.write(documentUtility.newDocumentFor(document, data));

But I’d like to instead preview the response in standard json format in outputview. Any idea how this can be achieved ? Any help would be appreciated . Thank you!

1 ACCEPTED SOLUTION

ptaylor
Employee
Employee

Yes, you’ll want to use the Jackson library’s ObjectMapper class for that.

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.core.type.TypeReference;
...
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
private static final TypeReference<Object> TYPE_REF = new TypeReference<Object>() {};
...
Object parsedResponse = OBJECT_MAPPER.readValue(response, TYPE_REF);

Note there are other versions of the readValue method that take a Reader or InputStream, which means you might be able to avoid reading the entire response as a String.

Hope that helps.

View solution in original post

21 REPLIES 21

@ptaylor : Yes I have uploaded it to my organization’s root shared project.
I see all the snaps on clicking the snap pack name. These are all the snaps included in the snap pack.

Screen Shot 2021-08-25 at 4.23.01 PM

NOTE: Create Account Settings UI shows up fine.

@DharaSP if you close the pipeline containing your snaps in Designer, and then re-open the pipeline are you able to inspect snap properties for any of your snaps ?

DharaSP
New Contributor

@mbowen: Closing the pipeline in Designer and re-opening it again now shows properties UI. But this wasn’t the case earlier ?Is this a recent updated to the application?

@DharaSP
No. I think this is a bug. I’ve recently seen this behavior. Let me chat with others to try to pinpoint the exact problem. At least the heavy hammer closing & re-opening pipeline allows you to access the snap properties. Expect another update.

DharaSP
New Contributor

@mbowen Thank you so much for the prompt reply!