Hello,
I want to fetch some items from a table (“UserLevel”), iterate through them and add a new field. Below is my code. The error message that I get is
“Type:“java.lang.ClassCastException”, Description:“com.mypackage.UserLevel cannot be cast to java.util.Map”, ExceptionClass:“ServiceException” {Msg:“none”, Cause:“none”}”
Isn’t the BackendlessCollection a collection of Map items, each representing the columns (key/value) in the UserLevel table?
Also, am I right in assuming that the default column “created” corresponds to a LocalDate java type?
public void formatDate() {
QueryOptions queryOptions = new QueryOptions(10, 0, "rating DESC");
BackendlessDataQuery dataQuery = new BackendlessDataQuery(queryOptions);
BackendlessCollection<Map> userLevels = Backendless.Data.of((Class)
UserLevel.class).find(dataQuery);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM dd, yyyy");
Iterator<Map> iterator = userLevels.getCurrentPage().iterator();
while (iterator.hasNext()) {
Map userLevelMap = iterator.next();
LocalDate d = (LocalDate)userLevelMap.get("created");
userLevelMap.put("createdFormatted", d.format(formatter));
Backendless.Persistence.of("UserLevel").save(userLevelMap);
}
}