Skip to content

Commit 8d4797e

Browse files
authored
Merge pull request #12 from zeroae/i/no-entities-in-json
Output all annotations in JSON format
2 parents 314e3c6 + 2e31f69 commit 8d4797e

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/main/java/co/zeroae/gate/App.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.IOException;
2020
import java.net.URL;
2121
import java.util.HashMap;
22+
import java.util.HashSet;
2223
import java.util.Objects;
2324

2425
/**
@@ -71,9 +72,20 @@ public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent in
7172
* @param responseType One of the supported response types
7273
*/
7374
private String encode(Document doc, String responseType) throws IOException {
75+
final FeatureMap exportOptions = Factory.newFeatureMap();
76+
77+
// Take *all* annotation types.
78+
final AnnotationSet defaultAnnots = doc.getAnnotations();
79+
final HashSet<String> annotationTypes = new HashSet<>();
80+
for (Annotation annotation: defaultAnnots.inDocumentOrder()) {
81+
annotationTypes.add(annotation.getType());
82+
}
83+
exportOptions.put("annotationTypes", annotationTypes);
84+
7485
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
7586
if (responseType.equals("application/json")) {
76-
gateJsonExporter.export(doc, baos);
87+
gateJsonExporter.setAnnotationTypes(doc.getAnnotationSetNames());
88+
gateJsonExporter.export(doc, baos, exportOptions);
7789
return baos.toString();
7890
}
7991
else {

src/test/java/co/zeroae/gate/AppTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void testApplicationJsonResponse() throws Exception {
6666
APIGatewayProxyRequestEvent input = new APIGatewayProxyRequestEvent()
6767
.withHttpMethod("POST")
6868
.withHeaders(Collections.unmodifiableMap(inputHeaders))
69-
.withBody("My name is Lambda Function and I approve this test.");
69+
.withBody("Today is Monday.");
7070
final TestContext context = new TestContext();
7171
final APIGatewayProxyResponseEvent result = app.handleRequest(input, context);
7272
assertEquals(result.getStatusCode().intValue(), 200);

0 commit comments

Comments
 (0)