本文整理汇总了Java中org.sonar.api.utils.text.JsonWriter.of方法的典型用法代码示例。如果您正苦于以下问题:Java JsonWriter.of方法的具体用法?Java JsonWriter.of怎么用?Java JsonWriter.of使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.sonar.api.utils.text.JsonWriter
的用法示例。
在下文中一共展示了JsonWriter.of方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeTo
import org.sonar.api.utils.text.JsonWriter; //导入方法依赖的package包/类
void writeTo(HttpServletResponse resp) throws IOException {
try (ServletOutputStream outputStream = resp.getOutputStream();
OutputStreamWriter writer = new OutputStreamWriter(outputStream, UTF_8);
JsonWriter json = JsonWriter.of(writer)) {
json.beginObject();
json.prop("code", code);
writePagination(json);
writeIssues(json);
writeStore(json);
writeHighlightings(json);
writeSymbolRefs(json);
writeErrors(json);
json.endObject();
}
resp.setStatus(200);
}
示例2: test
import org.sonar.api.utils.text.JsonWriter; //导入方法依赖的package包/类
@Test
public void test() throws IOException {
final Issue issue = ReflectionTestUtils.build(Issue.class, "status_", "RESOLVED", "resolution_", "FALSE-POSITIVE",
"assignee_", "admin", "comments_",
ReflectionTestUtils.build(Comments.class, "comments_",
Arrays.asList(ReflectionTestUtils.build(Comment.class, "markdown_", "Comment one"),
ReflectionTestUtils.build(Comment.class, "markdown_", "Comment two"))));
final IssueData data = IssueData.fromIssue(issue);
Assert.assertEquals("RESOLVED", data.getStatus());
Assert.assertEquals("FALSE-POSITIVE", data.getResolution());
Assert.assertEquals("admin", data.getAssignee());
Assert.assertEquals(Arrays.asList("Comment one", "Comment two"), data.getComments());
final String json;
try (final StringWriter writer = new StringWriter()) {
final JsonWriter jsonWriter = JsonWriter.of(writer);
jsonWriter.beginObject();
data.write(jsonWriter);
jsonWriter.endObject();
jsonWriter.close();
json = writer.toString();
}
Assert.assertEquals("{\"status\":\"RESOLVED\",\"resolution\":\"FALSE-POSITIVE\",\"assignee\":\"admin\",\"comments\":[\"Comment one\",\"Comment two\"]}", json);
final IssueData readData;
try (final ByteArrayInputStream bais = new ByteArrayInputStream(json.getBytes("UTF-8"));
final JsonReader reader = new JsonReader(bais)) {
reader.beginObject();
readData = IssueData.read(reader);
reader.endObject();
}
Assert.assertEquals("RESOLVED", readData.getStatus());
Assert.assertEquals("FALSE-POSITIVE", readData.getResolution());
Assert.assertEquals("admin", readData.getAssignee());
Assert.assertEquals(Arrays.asList("Comment one", "Comment two"), readData.getComments());
}
示例3: test
import org.sonar.api.utils.text.JsonWriter; //导入方法依赖的package包/类
@Test
public void test() throws IOException {
final Issue issue = ReflectionTestUtils.build(Issue.class, "rule_", "test:rule001", "component_",
"nl.future-edge.sonarqube.plugins:sonar-issueresolver-plugin:src/main/java/nl/futureedge/sonar/plugin/issueresolver/issues/IssueKey.java",
"textRange_", ReflectionTestUtils.build(TextRange.class, "startLine_", 13, "startOffset_", 65));
final Component component = ReflectionTestUtils.build(Component.class, "key_", "nl.future-edge.sonarqube.plugins:sonar-issueresolver-plugin:src/main/java/nl/futureedge/sonar/plugin/issueresolver/issues/IssueKey.java",
"longName_", "src/main/java/nl/futureedge/sonar/plugin/issueresolver/issues/IssueKey.java");
final List<Component> components = Arrays.asList(component);
final IssueKey key = IssueKey.fromIssue(issue, components);
final String json;
try (final StringWriter writer = new StringWriter()) {
final JsonWriter jsonWriter = JsonWriter.of(writer);
jsonWriter.beginObject();
key.write(jsonWriter);
jsonWriter.endObject();
jsonWriter.close();
json = writer.toString();
}
Assert.assertEquals(
"{\"longName\":\"src/main/java/nl/futureedge/sonar/plugin/issueresolver/issues/IssueKey.java\",\"rule\":\"test:rule001\",\"line\":13}",
json);
final IssueKey readKey;
try (final ByteArrayInputStream bais = new ByteArrayInputStream(json.getBytes("UTF-8"));
final JsonReader reader = new JsonReader(bais)) {
reader.beginObject();
readKey = IssueKey.read(reader);
reader.endObject();
}
Assert.assertEquals(key.hashCode(), readKey.hashCode());
Assert.assertEquals(key, readKey);
Assert.assertFalse(key.equals(null));
Assert.assertTrue(key.equals(key));
Assert.assertFalse(key.equals(new Object()));
}
示例4: newJsonWriter
import org.sonar.api.utils.text.JsonWriter; //导入方法依赖的package包/类
@Override
public JsonWriter newJsonWriter() {
return JsonWriter.of(new OutputStreamWriter(output()));
}