I've got the following reader configured:
@Configuration
public class ReaderConfig {
@Bean
public JsonItemReader<String> jsonItemReader(Resource resource) {
return new JsonItemReaderBuilder<String>()
.jsonObjectReader(new JacksonJsonObjectReader<>(String.class))
.resource(resource)
.name("jsonItemReader")
.build();
}
}
With this test:
@Test
public void jsonItemReaderTest() throws Exception {
ReaderConfig config = new ReaderConfig();
Resource sampleJsonResource = new ClassPathResource("sampleResponse.json");
JsonItemReader<String> reader = config.jsonItemReader(sampleJsonResource);
reader.open(new ExecutionContext());
String item = null;
List<String> results = new ArrayList<>();
do {
item = reader.read();
System.err.println(item);
if (!Objects.isNull(item)) {
results.add(item);
}
} while (item != null);
reader.close();
assertThat(results).hasSize(7);
}
and the following JSON:
[
"A",
"B",
"C",
"D",
"E",
"F",
"G"
]
However, the reader returns null. Trying to trace with the debugger, what I'm getting is that the parser returns back that it has a string at the beginning of the array and there's an expectation that there should instead be an opening brace. Any pointers on this? It seems like such an obvious use case that I'm surprised it isn't covered by the code.