'"Any" field in .realm file
I have a pre-initialized .realm file that I'm trying to access in Android Studio. I have used Realm browser to figure out the exact schema to model my classes after (i.e. field names and types), but I can't figure out what the Any type of the comments field (see screenshot below) should be in my code.
According to this, the field can only be a boolean, short, ìnt, long, float, double, String, Date, byte[], subclasses of RealmObject, or RealmList<? extends RealmObject>. I've tried a bunch of different types for the comments field, but I continue to get errors similar to the following:
io.realm.exceptions.RealmMigrationNeededException: Invalid type 'String' for field 'comments'
When I try to allow comments to be as generic as possible by making its type RealmObject, my code fails to even compile successfully:
/Users/name/AndroidStudioProjects/Project/app/build/intermediates/classes/debug/io/realm/ReportRealmProxy.java
Error:(147, 17) error: cannot find symbol variable RealmObjectRealmProxy
Error:(285, 48) error: cannot find symbol variable RealmObjectRealmProxy
Error:(330, 52) error: cannot find symbol variable RealmObjectRealmProxy
Error:(374, 41) error: cannot find symbol variable RealmObjectRealmProxy
Error:(420, 41) error: cannot find symbol variable RealmObjectRealmProxy
Finally, when I tried to use Realm Browser's automatic model code generation (File -> Save Model Definitions -> Save Java definitions...), the following code is produced:
import io.realm.RealmObject
public class Report extends RealmObject {
private String term;
private String year;
private int enrollment;
private Any comments;
private RealmList<Response> responses;
private RealmList<FacultyReport> facultyReports;
}
Unfortunately, neither Android Studio nor I understand what the Any class is - I can't find any mention of it online.
Any help would be much appreciated, as I am unable to load the data without exactly matching the model definitions used to create it. If there were a way to load all the data except the Report class/table, that would work too, because it is currently empty (as the screenshot shows). But, currently, even though it is empty, my inability to model it is preventing me from loading any objects at all!
Edit: Here is my Report.java class code:
import io.realm.RealmList;
import io.realm.RealmObject;
public class Report extends RealmObject {
private String term;
private String year;
private int enrollment;
private ???? comments;
private RealmList<Response> responses;
private RealmList<FacultyReport> facultyReports;
public ???? getComments() {
return comments;
}
public void setComments(???? comments) {
this.comments = comments;
}
// other getters and setters removed
}
Solution 1:[1]
It seems like Realm Swift was missing a few cases where it wouldn't catch unsupported property types in models in some cases, therefore treating it as an 'Any' type (a.k.a. 'mixed').
I have a PR fixing the issue which is now pending review: https://github.com/realm/realm-cocoa/pull/2496
Although we may change the approach we're taking.
Solution 2:[2]
Have you noticed that you can make the Browser create Java code for the Class Definitions (look in the File menu)?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | jpsim |
| Solution 2 | ast |

