Skip to content

Commit fe3f43f

Browse files
authored
Updated libraries, added pretty print
1 parent 120c351 commit fe3f43f

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

java/InkRecognition/quickstart/RecognizeInk.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,27 @@
88
import org.apache.http.impl.client.CloseableHttpClient;
99
import org.apache.http.impl.client.HttpClients;
1010
import org.apache.http.util.EntityUtils;
11+
import com.fasterxml.jackson.core.JsonParseException;
12+
import com.fasterxml.jackson.databind.JsonMappingException;
13+
import com.fasterxml.jackson.databind.ObjectMapper;
1114
import java.io.IOException;
1215
import java.nio.file.Files;
1316
import java.nio.file.Paths;
17+
import java.util.HashMap;
18+
import java.util.Map;
1419
// </imports>
1520

21+
/**
22+
* Library jars needed (add to a lib folder):
23+
* httpclient-4.5.11+
24+
* slf4j-jdk14-1.7.28+
25+
* httpcore-4.4.13+
26+
* commons-logging-1.2+
27+
* jackson-databind-2.10.2+
28+
* jackson-annotations-2.10.2+
29+
* jackson-core-2.10.2+
30+
*/
31+
1632
public class RecognizeInk {
1733
// <vars>
1834
// Add your Azure Ink Recognition subscription key to your environment variables.
@@ -36,7 +52,19 @@ static void recognizeInk(String requestData) {
3652
System.out.println("Sending an Ink recognition request.");
3753

3854
String result = sendRequest(rootUrl, inkRecognitionUrl, subscriptionKey, requestData);
39-
System.out.println(result);
55+
56+
// Pretty-print the JSON result
57+
try {
58+
ObjectMapper objectMapper = new ObjectMapper();
59+
Map<String, Object> response = objectMapper.readValue(result, HashMap.class);
60+
System.out.println(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(response));
61+
} catch (JsonParseException e) {
62+
e.printStackTrace();
63+
} catch (JsonMappingException e) {
64+
e.printStackTrace();
65+
} catch (IOException e) {
66+
e.printStackTrace();
67+
}
4068
}
4169
// </recognizeInk>
4270
// <sendRequest>

0 commit comments

Comments
 (0)