Skip to content

Commit 1be7440

Browse files
committed
Added jsonLinesRaw support to API
Also deprecated existing jsonLines method - no need for a boolean, though there's a general lack of consistency there in the API.
1 parent 855ae43 commit 1be7440

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

flux-cli/src/main/java/com/marklogic/flux/api/AggregateJsonFilesImporter.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,27 @@ interface ReadJsonFilesOptions extends ReadFilesOptions<ReadJsonFilesOptions> {
1717
/**
1818
* @param value set to true to read JSON Lines files. Defaults to reading files that either contain an array
1919
* of JSON objects or a single JSON object.
20+
* @deprecated since 1.1.2; use {@code jsonLines()} instead.
2021
*/
22+
@SuppressWarnings("java:S1133") // Telling Sonar we don't need a reminder to remove this some day.
23+
@Deprecated(since = "1.1.2", forRemoval = true)
2124
ReadJsonFilesOptions jsonLines(boolean value);
2225

2326
/**
27+
* Call this to read JSON Lines files. Otherwise, defaults to reading files that either contain an array of
28+
* JSON objects or a single JSON object.
29+
*
2430
* @since 1.1.2
2531
*/
26-
ReadJsonFilesOptions jsonLinesRaw(boolean value);
32+
ReadJsonFilesOptions jsonLines();
33+
34+
/**
35+
* Call this to read JSON Lines files "as is", without any alteration to the documents associated with each
36+
* line.
37+
*
38+
* @since 1.1.2
39+
*/
40+
ReadJsonFilesOptions jsonLinesRaw();
2741

2842
ReadJsonFilesOptions encoding(String encoding);
2943

flux-cli/src/main/java/com/marklogic/flux/impl/importdata/ImportAggregateJsonFilesCommand.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,14 @@ public ReadJsonFilesOptions jsonLines(boolean value) {
101101
}
102102

103103
@Override
104-
public ReadJsonFilesOptions jsonLinesRaw(boolean value) {
105-
this.jsonLinesRaw = value;
104+
public ReadJsonFilesOptions jsonLines() {
105+
this.jsonLines = true;
106+
return this;
107+
}
108+
109+
@Override
110+
public ReadJsonFilesOptions jsonLinesRaw() {
111+
this.jsonLinesRaw = true;
106112
return this;
107113
}
108114

flux-cli/src/test/java/com/marklogic/flux/api/AggregateJsonFilesImporterTest.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void test() {
2121
.connectionString(makeConnectionString())
2222
.from(options -> options
2323
.paths("src/test/resources/delimited-files/custom-delimiter-json.txt")
24-
.jsonLines(true)
24+
.jsonLines()
2525
.additionalOptions(Map.of("lineSep", ":\n")))
2626
.to(options -> options
2727
.permissionsString(DEFAULT_PERMISSIONS)
@@ -47,4 +47,20 @@ void missingPath() {
4747
FluxException ex = assertThrowsFluxException(() -> importer.execute());
4848
assertEquals("Must specify one or more file paths", ex.getMessage());
4949
}
50+
51+
@Test
52+
void jsonLinesRaw() {
53+
Flux.importAggregateJsonFiles()
54+
.connectionString(makeConnectionString())
55+
.from(options -> options
56+
.paths("src/test/resources/delimited-files/different-objects.txt")
57+
.jsonLinesRaw()
58+
)
59+
.to(options -> options
60+
.collections("json-lines")
61+
.permissionsString(DEFAULT_PERMISSIONS)
62+
).execute();
63+
64+
assertCollectionSize("json-lines", 2);
65+
}
5066
}

flux-cli/src/test/java/com/marklogic/flux/api/JsonLinesFilesExporterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void test(@TempDir Path tempDir) {
2424
Flux.importAggregateJsonFiles()
2525
.from(options -> options
2626
.paths(tempDir.toFile().getAbsolutePath())
27-
.jsonLines(true))
27+
.jsonLines())
2828
.connectionString(makeConnectionString())
2929
.to(options -> options
3030
.permissionsString(DEFAULT_PERMISSIONS)

0 commit comments

Comments
 (0)