当前位置: 首页>>代码示例>>Java>>正文


Java JsonWriter.of方法代码示例

本文整理汇总了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);
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:17,代码来源:ResponseMessage.java

示例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());
}
 
开发者ID:willemsrb,项目名称:sonar-issueresolver-plugin,代码行数:40,代码来源:IssueDataTest.java

示例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()));
}
 
开发者ID:willemsrb,项目名称:sonar-issueresolver-plugin,代码行数:40,代码来源:IssueKeyTest.java

示例4: newJsonWriter

import org.sonar.api.utils.text.JsonWriter; //导入方法依赖的package包/类
@Override
public JsonWriter newJsonWriter() {
	return JsonWriter.of(new OutputStreamWriter(output()));
}
 
开发者ID:willemsrb,项目名称:sonar-issueresolver-plugin,代码行数:5,代码来源:MockResponse.java


注:本文中的org.sonar.api.utils.text.JsonWriter.of方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。