88import org .apache .http .impl .client .CloseableHttpClient ;
99import org .apache .http .impl .client .HttpClients ;
1010import 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 ;
1114import java .io .IOException ;
1215import java .nio .file .Files ;
1316import 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+
1632public 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