Skip to content

Commit

Permalink
Avoid wrapping single record in list (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsteeg committed Sep 3, 2021
1 parent 7b47a1c commit b4e056b
Showing 1 changed file with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,24 @@ public void resetRecordCount() {
@Override
public void process(final String json) {
assert !isClosed();
final List<String> records = recordPath.isEmpty() ? Arrays.asList(json)
: matches(JsonPath.read(json, recordPath));
records.forEach(record -> {
createParser(record);
try {
decode();
} catch (final IOException e) {
throw new MetafactureException(e);
} finally {
closeParser();
}
});
if (recordPath.isEmpty()) {
processRecord(json);
} else {
matches(JsonPath.read(json, recordPath)).forEach(record -> {
processRecord(record);
});
}
}

private void processRecord(String record) {
createParser(record);
try {
decode();
} catch (final IOException e) {
throw new MetafactureException(e);
} finally {
closeParser();
}
}

private List<String> matches(Object obj) {
Expand Down

0 comments on commit b4e056b

Please sign in to comment.