โ05-07-2021 09:05 AM
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!
Solved! Go to Solution.
โ05-11-2021 09:45 AM
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.
โ08-26-2021 10:34 AM
Update: Iโve spoken to our UI team and this is a known issue. In fact, it has been fixed and is currently under code review. It will be released in the next patch. Until then you can use the close and re-open pipeline trick to restore properties for custom snaps.
โ08-26-2021 11:37 AM
Sounds good. Thank you @mbowen for the update!