'Reading JSON file list returns null (can not read file)

I'm trying to read a file that contains a json object but it returns null. here is my json file

[   
{"VersionNumber": 200,
"TitleFA": "TitleFA2",
"DescriptionFA": "DescriptionFA2",
"TitleEN": "TitleEN2",
"DescriptionEN": "DescriptionEN2",
"Priority": 1  },

{"VersionNumber": 100,
"TitleFA": "TitleFA1",
"DescriptionFA": "DescriptionFA1",
"TitleEN": "TitleEN1",
"DescriptionEN": "DescriptionEN1",
"Image": "Image1",
"Priority": 1  } 
]

Here is the Class that I'm trying to map it to

@JsonIgnoreProperties(ignoreUnknown = true)
public class OnBoardingItemsModel {
 public int VersionNumber;
 public String TitleFA;
 public String DescriptionFA;
 public String TitleEN;
 public String DescriptionEN;
 public String Image;
 public int Priority; }

Here is the code I'm using it my fragment to read the file. Also my json file is in the same directory as my fragment class

    private List<OnBoardingItemsModel> mOnBoardingItems;
    ObjectMapper mapper = new ObjectMapper();
    mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);

    try {
        mOnBoardingItems = Arrays.asList(mapper.readValue(new File("OnBoardingItems.json"), OnBoardingItemsModel[].class));

    } catch (IOException e) {
        e.printStackTrace();
    }

I tried different ways but mOnBoardingItems is always null in the end. I also tries this code and it didn't work: Java Android – Read JSON file from assets using Gson

Edit: I tried this and it returned false. I don't know why it's unable to read the file

    File file = new File("OnBoardingItems.json");

    Log.v("canreadfile", String.valueOf(file.canRead()));
    Log.v("isfileee", String.valueOf(file.isFile()));

I have no idea what else I should check I would appreciate it if someone could help



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source