Skip to content

Commit b4e056b

Browse files
committed
Avoid wrapping single record in list (#382)
1 parent 7b47a1c commit b4e056b

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

metafacture-json/src/main/java/org/metafacture/json/JsonDecoder.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,24 @@ public void resetRecordCount() {
132132
@Override
133133
public void process(final String json) {
134134
assert !isClosed();
135-
final List<String> records = recordPath.isEmpty() ? Arrays.asList(json)
136-
: matches(JsonPath.read(json, recordPath));
137-
records.forEach(record -> {
138-
createParser(record);
139-
try {
140-
decode();
141-
} catch (final IOException e) {
142-
throw new MetafactureException(e);
143-
} finally {
144-
closeParser();
145-
}
146-
});
135+
if (recordPath.isEmpty()) {
136+
processRecord(json);
137+
} else {
138+
matches(JsonPath.read(json, recordPath)).forEach(record -> {
139+
processRecord(record);
140+
});
141+
}
142+
}
143+
144+
private void processRecord(String record) {
145+
createParser(record);
146+
try {
147+
decode();
148+
} catch (final IOException e) {
149+
throw new MetafactureException(e);
150+
} finally {
151+
closeParser();
152+
}
147153
}
148154

149155
private List<String> matches(Object obj) {

0 commit comments

Comments
 (0)