JSONParser implements FileSerializer<ResultType> { @Override public List<ResultType> readFile(File path) throws IOException { if (!path.exists()) { return Collections.emptyList(); } MappingIterator<ResultType> iterator = mapper.reader(resultType).readValues(path); return Lists.newArrayList(iterator); } JSONParser(Class<ResultType> resultType); @Override List<ResultType> readFile(File path); @Override void writeFile(File path, List<ResultType> models);  }
@Test public void testParseJSONShouldCreateObject() throws Exception { FileUtils.write(testfile, "[ " + "{ \"a\":42, \"b\":\"foo\", \"c\":7 }, " + "{ \"a\":21, \"b\":\"bar\", \"c\":9 }" + "]"); List<TestModel> testModels = parser.readFile(testfile); assertThat(testModels.size(), is(2)); TestModel model = testModels.get(0); assertThat(model.getA(), is(42)); assertThat(model.getB(), is("foo")); assertThat(model.getC(), is(7L)); model = testModels.get(1); assertThat(model.getA(), is(21)); assertThat(model.getB(), is("bar")); assertThat(model.getC(), is(9L)); }