how to read Json Array file and pass it as a function arguments for testing the function n java
here i need to pass the properties argument to the below function.
my function is below:
public static void convertDateAttrsToString(JSONArray properties, BasicDBObject attributesObj) {
if (properties != null && !properties.isEmpty()) {
for (Object property1 : properties) {
JSONObject property = (JSONObject) property1;
if (attributesObj.containsField(attributeId)) {
BasicDBObject attribute = (BasicDBObject) attributesObj.get(attributeId);
if (attribute.getString(Constants.CONSTANT_DATATYPE).equals(Constants.CONSTANT_DATE)) {
property.put(attributeId, convertToLocalDateTimeViaInstant((Date) property.get("value")));
}
}
}
}
}
my json array file is JsonArray.json
{
"name":"John",
"age":30,
"cars":[ "Ford", "BMW", "Fiat" ]
}
What I have tried:
URL resource = App.class.getClassLoader().getResource("JsonArray.json")
String json = resource.toString();
FileReader reader = new FileReader(resource.getFile());
// Read JSON file
Object obj = JsonParser.parseList();
JSONArray infoList = (JSONArray) obj;
it shows error .anyhelp wouldbe appreciated