0

I have a json file like this :

[
{
    "Teacher Code": "1",
    "Teacher Name": "Papadopoulos",
    "MaxHoursPerDay":5,
    "MaxHoursPerWeek":18,
    "Teacher Lessons": [
        "Fysikh Agwgh"
    ]
},
{
    "Teacher Code": "2",
    "Teacher Name": "Nikolaou",
    "MaxHoursPerDay":4,
    "MaxHoursPerWeek":8,
    "Teacher Lessons": [
        "Thriskeytika"
    ]
},
{
    "Teacher Code": "3",
    "Teacher Name": "Anastasopoulou",
    "MaxHoursPerDay":4,
    "MaxHoursPerWeek":18,
    "Teacher Lessons": [
        "Ksenh Glwssa 1"
    ]
}...

and I want to iterate through that file and create java objects using jackson objectMapper and store those items in an arrayList.Here is what I have tried:

ObjectMapper mapper = new ObjectMapper();
File file = new File("Teachers.txt");
ArrayList<Teacher> tList = mapper.readValue(file, new TypeReference<ArrayList<Teacher>>(){};

But is shows me the error: type TypeReference does not take parameters. Whats the best way to do this without knowing the length of the json file?

3
  • Please show what you've tried and then let us know how your attempt is not working well for you. Commented Nov 4, 2017 at 14:08
  • Use a List<Teacher> object as the top class. Commented Nov 4, 2017 at 14:08
  • I have edited the question Commented Nov 4, 2017 at 14:23

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.