A piece of code that I have refactored out of my main method to a separate method is having an issue with type inference when iterated over.
val resourceId = resourceIdjsonobject.get("resourceId").toString
val sensorJson = resourceIdjsonobject.get("stat-list").asInstanceOf[JSONObject].get("stat").asInstanceOf[JSONArray]
val list = new ListBuffer[Tuple2[JSONObject, String]]()
for (y <- sensorJson) {
println(y)
}
list
This is the code that I have specified within my main method and a separate method. Using Ctrl-Q I have found that sensorJson and all variables aside from y are correctly inferred, y is being inferred as Any which is incorrect as within the main method it is inferred as JSONObject.
This is the error I get on compilation:
value foreach is not a member of net.minidev.json.JSONArray
I have tried using y:JSONObject
to specify the type of y though I then get the error on compilation:
value filter is not a member of net.minidev.json.JSONArray
Where am I going wrong?