CSV 转换:
基准测试:
你有几个库来执行 CSV Java 对象之间的转换,这里是不同库的基准:
| Library |
Read (rec/sec) |
Write (rec/sec) |
Dependencies |
Size (KiB) |
| Commons CSV |
1,128,102 |
3,354,703 |
no |
50 |
| FastCSV |
4,738,726 |
5,034,953 |
no |
31 |
| Jackson CSV |
3,770,602 |
3,995,294 |
yes |
2,040 |
| Java CSV |
1,922,189 |
2,732,843 |
no |
13 |
| Opencsv |
1,085,935 |
1,808,982 |
yes |
2,625 |
| Sfm+ASM |
5,164,967 |
1,901,154 |
yes |
1.498 |
| Sfm-ASM |
4,652,517 |
1,901,154 |
yes |
1,498 |
| Super CSV |
1,406,090 |
1,730,984 |
no |
96 |
| Univocity |
3,594,900 |
4,050,255 |
no |
437 |
有关此基准的更多信息,您可以访问此网站:https://github.com/osiegmar/JavaCsvBenchmarkSuite#results
FastCSV:
迭代读取一些带有header的CSV数据
NamedCsvReader.builder().build("header 1,header 2\nfield 1,field 2")
.forEach(row -> row.getField("header 2"));
有关 FastCSV 的更多信息,您可以访问此网站:https://github.com/osiegmar/FastCSV
JSON 转换:
基准测试:
你有几个库来执行 Json Java 对象之间的转换,这里是不同库的基准:
有关此基准的更多信息,您可以访问此站点:https://github.com/ngs-doo/dsl-json
杰克逊数据绑定:
json字符串到java对象的转换:
String json = "{\"name\":\"Hassan\",\"age\":23}";
Person person = new ObjectMapper().readValue(json, Person.class);
有关 jackson-databind 的更多信息,您可以访问此网站:https://github.com/FasterXML/jackson-databind
CouchBase 插入:
Java 中的批量插入示例:
protected void doWork() {
final String key = "javaDevguideExampleBulkInsert";
// Create a JSON document content
final JsonObject content = JsonObject.create().put("item", "A bulk insert test value");
// Describe what we want to do asynchronously using RxJava Observables:
ReactiveCollection reactiveCollection = collection.reactive();
Flux<MutationResult> resultFlux = Flux.range(0, 10)
.map(index -> { return key + "_" + index; })
.flatMap(k -> reactiveCollection.upsert(k, content));
resultFlux.subscribe(System.out::println);
}
此代码来自 CouchBase 的 official docs-sdk-java