本文整理汇总了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();
}
}
示例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)));
}
示例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);
}
示例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;
}
示例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();
}
}
}
示例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);
}
}
示例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;
}
示例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)));
}