Skip to content

Commit 74dc79f

Browse files
committed
Change print_record() Fix function to always output JSON. (#238)
1 parent 3e9a2fb commit 74dc79f

File tree

2 files changed

+7
-22
lines changed

2 files changed

+7
-22
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ paste("my.string", "~Hi", "a", "~how are you?")
307307

308308
##### `print_record`
309309

310-
Prints the current record either to standard output or to a file.
310+
Prints the current record as JSON either to standard output or to a file.
311311

312312
Parameters:
313313

@@ -321,7 +321,6 @@ Options:
321321
- `footer`: Footer which is output after the record. (Default: `\n`)
322322
- `header`: Header which is output before the record. (Default: Empty string)
323323
- `id`: Field name which contains the record ID; if found, will be included before the prefix. (Default: `_id`)
324-
- `json`: Whether to encode the record as JSON. (Default: `false`)
325324
- `pretty`: Whether to use pretty printing. (Default: `false`)
326325

327326
```perl
@@ -332,8 +331,8 @@ E.g.:
332331

333332
```perl
334333
print_record("Before transformation")
335-
print_record(destination: "record-%03d.gz", header: "After transformation: ")
336-
print_record(destination: "record-%2$s.json", id: "001", json: "true", pretty: "true")
334+
print_record(destination: "record-%2$s.json", id: "001", pretty: "true")
335+
print_record(destination: "record-%03d.json.gz", header: "After transformation: ")
337336
```
338337

339338
##### `random`

metafix/src/main/java/org/metafacture/metafix/FixMethod.java

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ public void apply(final Metafix metafix, final Record record, final List<String>
222222
final String destination = options.getOrDefault("destination", ObjectWriter.STDOUT);
223223
final Value idValue = record.get(options.getOrDefault("id", StandardEventNames.ID));
224224

225-
final boolean json = getBoolean(options, "json");
226225
final boolean pretty = getBoolean(options, "pretty");
227226

228227
final String id = Value.isNull(idValue) ? "" : idValue.toString();
@@ -238,24 +237,11 @@ public void apply(final Metafix metafix, final Record record, final List<String>
238237
withOption(options, "footer", writer::setFooter);
239238
withOption(options, "header", writer::setHeader);
240239

241-
boolean written = false;
242-
243-
if (json) {
244-
try {
245-
writer.process(prefix + record.toJson(pretty));
246-
written = true;
247-
}
248-
catch (final IOException e) {
249-
}
240+
try {
241+
writer.process(prefix + record.toJson(pretty));
250242
}
251-
252-
if (!written) {
253-
if (pretty) {
254-
record.forEach((f, v) -> writer.process(prefix + f + "=" + v));
255-
}
256-
else {
257-
writer.process(prefix + record);
258-
}
243+
catch (final IOException e) {
244+
// Log a warning? Print string representation instead?
259245
}
260246

261247
writer.closeStream();

0 commit comments

Comments
 (0)