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


Java Gson类代码示例

本文整理汇总了Java中gherkin.deps.com.google.gson.Gson的典型用法代码示例。如果您正苦于以下问题:Java Gson类的具体用法?Java Gson怎么用?Java Gson使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Gson类属于gherkin.deps.com.google.gson包,在下文中一共展示了Gson类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: merge

import gherkin.deps.com.google.gson.Gson; //导入依赖的package包/类
public void merge(Path mergedReport) throws IOException {
	List<Map<String, Object>> features = new ArrayList<Map<String, Object>>();
	for (Path reportFile : reportFiles) {
		features.addAll(readSingleReport(reportFile));
	}

	Path reportDirectory = mergedReport.getParent();
	if (reportDirectory != null)
		Files.createDirectories(reportDirectory);
	try (BufferedWriter bw = new BufferedWriter(new FileWriter(mergedReport.toFile()))) {
		Gson gson = new GsonBuilder().registerTypeAdapter(Double.class, new JsonDoubleSerializer()).setPrettyPrinting()
				.create();
		bw.write(gson.toJson(features));
		bw.close();
	}
}
 
开发者ID:djb61,项目名称:parallel-cucumber-jvm,代码行数:17,代码来源:JsonReportMerger.java

示例2: change_default_language

import gherkin.deps.com.google.gson.Gson; //导入依赖的package包/类
@Test
public void change_default_language() throws Exception {
    Gson gson = new Gson();
    JsonParser jsonParser = new JsonParser();
    TokenMatcher matcher = new TokenMatcher("no");
    Parser<GherkinDocument> parser = new Parser<>(new AstBuilder());

 GherkinDocument gherkinDocument = parser.parse("Egenskap: i18n support\n", matcher);

    assertEquals(jsonParser.parse("" +
            "{\"feature\":{\"tags\":[]," +
            "    \"language\":\"no\"," +
            "    \"keyword\":\"Egenskap\"," +
            "    \"name\":\"i18n support\"," +
            "    \"children\":[]," +
            "    \"type\":\"Feature\"," +
            "    \"location\":{\"line\":1,\"column\":1}}," +
            "\"comments\":[]," +
            "\"type\":\"GherkinDocument\"}"),
            jsonParser.parse(gson.toJson(gherkinDocument)));
}
 
开发者ID:cucumber,项目名称:gherkin-java,代码行数:22,代码来源:ParserTest.java

示例3: iRunGradle

import gherkin.deps.com.google.gson.Gson; //导入依赖的package包/类
@When("^I run Gradle$")
public void iRunGradle() throws Throwable {
  result = GradleRunner.create()
      .withPluginClasspath()
      .withProjectDir(projectDir.toFile())
      .withArguments("--offline", "-q", "--stacktrace", "doReport")
      .build();

  scenario.write(result.getOutput());

  Path reportFile = projectDir.resolve("report.json");
  String reportString = new String(Files.readAllBytes(reportFile));
  report = new Gson().fromJson(reportString, JsonElement.class).getAsJsonObject();
  scenario.write(reportString);
}
 
开发者ID:bsideup,项目名称:gradle-maven-sync-plugin,代码行数:16,代码来源:GradleStepdefs.java

示例4: getGson

import gherkin.deps.com.google.gson.Gson; //导入依赖的package包/类
private Gson getGson() {
    try {
        Method gsonMethod = JSONFormatter.class.getDeclaredMethod("gson");
        gsonMethod.setAccessible(true);
        return (Gson) gsonMethod.invoke(this.jsonFormatter);
    } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:eu-evops,项目名称:cucumber-runner-maven-plugin,代码行数:11,代码来源:StreamingJSONFormatter.java

示例5: main

import gherkin.deps.com.google.gson.Gson; //导入依赖的package包/类
public static void main(String[] argv) throws IOException {
    final Gson gson = new GsonBuilder().create();

    List<String> args = new ArrayList<>(asList(argv));
    List<String> paths = new ArrayList<>();

    boolean printSource = true;
    boolean printAst = true;
    boolean printPickles = true;

    while (!args.isEmpty()) {
        String arg = args.remove(0).trim();

        switch (arg) {
            case "--no-source":
                printSource = false;
                break;
            case "--no-ast":
                printAst = false;
                break;
            case "--no-pickles":
                printPickles = false;
                break;
            default:
                paths.add(arg);
        }
    }

    SourceEvents sourceEvents = new SourceEvents(paths);
    GherkinEvents gherkinEvents = new GherkinEvents(printSource, printAst, printPickles);
    for (SourceEvent sourceEventEvent : sourceEvents) {
        for (CucumberEvent cucumberEvent : gherkinEvents.iterable(sourceEventEvent)) {
            Stdio.out.write(gson.toJson(cucumberEvent));
            Stdio.out.write("\n");
            Stdio.out.flush();
        }
    }
}
 
开发者ID:mauriciotogneri,项目名称:green-coffee,代码行数:39,代码来源:Main.java

示例6: readSingleReport

import gherkin.deps.com.google.gson.Gson; //导入依赖的package包/类
private List<Map<String, Object>> readSingleReport(Path reportFile) throws IOException {
	try (BufferedReader br = new BufferedReader(new FileReader(reportFile.toFile()))) {
		Type listType = new TypeToken<List<Map<String, Object>>>() {
		}.getType();
		return new Gson().fromJson(br, listType);
	}
}
 
开发者ID:djb61,项目名称:parallel-cucumber-jvm,代码行数:8,代码来源:JsonReportMerger.java

示例7: convertReportDataToJson

import gherkin.deps.com.google.gson.Gson; //导入依赖的package包/类
private String convertReportDataToJson(List<ThreadTimelineData> reportData) {
	Gson gson = new GsonBuilder().setPrettyPrinting().create();
	String json = gson.toJson(reportData);
	return json;
}
 
开发者ID:djb61,项目名称:parallel-cucumber-jvm,代码行数:6,代码来源:ThreadExecutionReporter.java

示例8: parses_feature_after_parse_error

import gherkin.deps.com.google.gson.Gson; //导入依赖的package包/类
@Test
public void parses_feature_after_parse_error() throws Exception {
    Gson gson = new Gson();
    JsonParser jsonParser = new JsonParser();
    String in1 = "" +
            "# a comment\n" +
            "Feature: Foo\n" +
            "  Scenario: Bar\n" +
            "    Given x\n" +
            "      ```\n" +
            "      unclosed docstring\n";
    String in2 = "" +
            "Feature: Foo\n" +
            "  Scenario: Bar\n" +
            "    Given x\n" +
            "      \"\"\"\n" +
            "      closed docstring\n" +
            "      \"\"\"";
    TokenMatcher matcher = new TokenMatcher();
    Parser<GherkinDocument> parser = new Parser<>(new AstBuilder());

    try {
        parser.parse(in1, matcher);
        fail("ParserException expected");
    } catch (ParserException e) {
        // pass
    }
    GherkinDocument gherkinDocument = parser.parse(in2, matcher);

    assertEquals(jsonParser.parse("" +
            "{\"feature\":{\"tags\":[]," +
            "    \"language\":\"en\"," +
            "    \"keyword\":\"Feature\"," +
            "    \"name\":\"Foo\"," +
            "    \"children\":[{" +
            "        \"tags\":[]," +
            "        \"keyword\":\"Scenario\"," +
            "        \"name\":\"Bar\"," +
            "        \"steps\":[{" +
            "            \"keyword\":\"Given \"," +
            "            \"text\":\"x\"," +
            "            \"argument\":{" +
            "                \"content\":\"closed docstring\"," +
            "                \"type\":\"DocString\"," +
            "                \"location\":{\"line\":4,\"column\":7}}," +
            "            \"type\":\"Step\"," +
            "            \"location\":{\"line\":3,\"column\":5}}]," +
            "        \"type\":\"Scenario\"," +
            "        \"location\":{\"line\":2,\"column\":3}}]," +
            "    \"type\":\"Feature\"," +
            "    \"location\":{\"line\":1,\"column\":1}}," +
            "\"comments\":[]," +
            "\"type\":\"GherkinDocument\"}"),
            jsonParser.parse(gson.toJson(gherkinDocument)));
}
 
开发者ID:cucumber,项目名称:gherkin-java,代码行数:56,代码来源:ParserTest.java


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