I have a JSON file containing millions of records. I'd like to use a Jackson iterator to read the records one at a time and perform an action for each one. Here's the code so far.
MappingIterator<MyClass> iterator = new ObjectMapper()
.readerFor(MyClass.class)
.readValues(file);
while (iterator.hasNext()) {
MyClass object = iterator.next();
...
}
The problem is that a few of the records are invalid due to missing quotes or illegal characters. This causes Jackson to throw an exception and quit. How can I tell Jackson to skip these records and continue to parse the remaining valid records?