Scala loop returns as Unit and compiler points to "for" syntax?
- by DeLongey
Seems like Unit is the theme of my troubles today. I'm porting a JSON deserializer that uses Gson and when it comes to this for loop:
def deserialize(json:JsonElement,
typeOfT:Type,
context:JsonDeserializationContext) = {
var eventData = new EventData(null, null)
var jsonObject = json.getAsJsonObject
for(entry <- jsonObject.entrySet()) {
var key = entry.getKey()
var element = entry.getValue()
element
if("previous_attributes".equals(key)) {
var previousAttributes = new scala.collection.mutable.HashMap[String, Object]()
populateMapFromJSONObject(previousAttributes, element.getAsJsonObject())
eventData.setPreviousAttributes(previousAttributes)
eventData
} else if ("object".equals(key)) {
val `type` = element.getAsJsonObject().get("object").getAsString()
var cl = objectMap.get(`type`).asInstanceOf[StripeObject]
var `object` = abstractObject.retrieve(cl, key)
eventData.setObject(`object`)
eventData
}
}
}
The compiler spits out the error type mismatch; found : Unit required: com.stripe.EventData and it points to this line here: for(entry <- jsonObject.entrySet())
Questions
Confirm that it is indeed the Gson method entrySet() appearing as unit?
If not, what part of the code is creating the issue? I've set return types/values for eventData class methods
Is there a workaround for the Gson Unit issue?
Thanks!