use of org.languagetool.Experimental in project languagetool by languagetool-org.
the class RuleMatchesAsJsonSerializer method ruleMatchesToJson.
/**
* @param incompleteResults use true to indicate that results are incomplete (e.g. due to a timeout) - a 'warnings'
* section will be added to the JSON
* @since 3.7
*/
@Experimental
public String ruleMatchesToJson(List<RuleMatch> matches, String text, int contextSize, Language lang, boolean incompleteResults) {
ContextTools contextTools = new ContextTools();
contextTools.setEscapeHtml(false);
contextTools.setContextSize(contextSize);
contextTools.setErrorMarkerStart(START_MARKER);
contextTools.setErrorMarkerEnd("");
StringWriter sw = new StringWriter();
try {
try (JsonGenerator g = factory.createGenerator(sw)) {
g.writeStartObject();
writeSoftwareSection(g);
writeWarningsSection(g, incompleteResults);
writeLanguageSection(g, lang);
writeMatchesSection(g, matches, text, contextTools);
g.writeEndObject();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return sw.toString();
}
Aggregations