Q:

Java Error while CSV to Json conversion. forType and readAll method

import java.io.*;
import java.util.*;
import com.fasterxml.jackson.databind.MappingIterator;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
import com.fasterxml.jackson.databind.MappingIterator.*;

public class CsvtoJson {
       public static void main(String args[]) throws Exception {
              File input = new File("input.csv");
              try {
                 CsvSchema csv = CsvSchema.emptySchema().withHeader();
                 CsvMapper csvMapper = new CsvMapper();
                 MappingIterator<Map<?, ?>> mappingIterator =  csvMapper.reader().forType(Map.class).with(csv).readValues(input);
                 List<Map<?, ?>> list = mappingIterator.readAll();
                System.out.println(list);
              } catch(Exception e) {
                 e.printStackTrace();
              }
           }
        }

Compilation Error:-
The method forType(Class) is undefined for the type ObjectReader
The method readAll() is undefined for the type MappingIterator<Map>
Trying to convert a big CSV file into JSON with Jackson library but I am stuck with this error. All jars all correctly added in the build path.

A:

The code works fine for me (JDK13), I think you have dependency problem. Please make sure you have jars for these dependencies(versions are not much important):
com.fasterxml.jackson.core:jackson-annotations:2.11.1
com.fasterxml.jackson.core:jackson-core:2.11.1
com.fasterxml.jackson.core:jackson-databind:2.11.1
com.fasterxml.jackson.dataformat:jackson-dataformat-csv:2.11.1

Note: It is much easy to create a maven project with an IDE. When you create a maven project add this dependecy to your maven pom file.
<dependency>
    <groupId>com.fasterxml.jackson.dataformat</groupId>
    <artifactId>jackson-dataformat-csv</artifactId>
    <version>2.11.1</version>
</dependency>

