-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Usage of parceler (@Parcel) with Realm.io (Android) #57
Comments
I have not looked into Realm deeply, but I'm disappointed to see it introduces a base class that you have to extend. There's a couple of options here: First, you could define a Third, could you define your RealmObject as a wrapper instead (again, I'm nearly completely ignorant on Realm)?: public class FeedRealmObject extends RealmObject {
Feed feed;
}
@Parcel
public class Feed {
//...
} |
I figured I'd go ahead and implement the scan limit (#59) since it was a natural next step. I've also pushed this to 0.2.16-SNAPSHOT if you'd like to try it out. |
Thanks, should it be in the Maven repo? What should i put in my build.girdle instead of Many thanks |
You need to add the maven central snapshots repo:
And update the parceler dependency to:
Keep in mind that SNAPSHOTS are volatile... without notice I may redact the current functionality. That being said, give it a try and let me know if it works for you. |
Thanks, i got an error saying: |
Thanks, I found my mistake here : http://stackoverflow.com/questions/20574111/add-maven-repository-to-build-gradle |
Due to constraints with Realm, I need to put variables as public, while Parceler wants private (for speed) So I need to do : @Parcel(analysisLimit = RealObject.class, Parcel.Serialization.METHOD ) is this the right syntax inside the bracket? Thanks again |
Looks about right: @Parcel(value = Parcel.Serialization.METHOD, analysisLimit = RealmObject.class) I'm not sure what you mean by Parceler wants private. Parceler will warn you that it will use reflection if using the |
Apologies, I meant Realm.io wants the class properties to be private (and having getter/setter), while if I put private properties without Serialization.METHOD, Parceler won't accept. hence I need to put both the arguments inside the brackets for both packages (parceler, realm) to work |
Oh OK, yes, |
By the way, I think I'm going to change the name of this Serialization technique to |
@somghosh, how did this work out for you? |
Thanks a lot @johncarl81 . I used it and it worked out from the Parceler point of view (meaning that the parcelling method stopped at the specified limit). So it works for simple Realm objects. However, the JSON string I get from sever is as a compound Pojo (class inside a class) and hence things did not work from the Realm point of view. I would still encourage you to put this up as a revision, as for simple objects, Parceler can be used with Realm now. Many thanks |
Thinking about this more, we could do something like specify exactly what classes are analyzed, like so: @Parcel(value = Parcel.Serialization.METHOD, analyze = {One.class, Three.class)
class One extends Two{}
class Two extends Three{}
class Three extends BaseClass{} Which would offer even more flexability. What do you think @somghosh? |
+1, not working with ActiveAndroid too. |
@johncarl81 I think that would solve the problem. Many thanks |
@somghosh not working with snapshot, analysisLimit doesn't exist. |
@ppamorim I've tried 0.2.16-SNAPSHOT with ActiveAndroid 3.1.0-SNAPSHOT (and Retrofit) and it seems working flawless so far. @Parcel(value = Parcel.Serialization.BEAN, analysisLimit = SMS.class)
@Table(name = "SMS")
public class SMS extends Model {
@SerializedName("id")
@Column(name = "smsid", index = true, unique = true, onUniqueConflict = Column.ConflictAction.FAIL)
String id;
// etc.
} @johncarl81 many thanks for your work! I really appreciate it! |
@ppamorim, @dracek, @ppamorim Any thoughts on a more specific approach mentioned above: @Parcel(value = Parcel.Serialization.METHOD, analyze = {One.class, Three.class)
class One extends Two{}
class Two extends Three{}
class Three extends BaseClass{} ^ Where only The One and Three class would be analyzed. This allows much more control and variability to the property with the drawback of being more verbose. |
This is implemented and deployed in version 0.2.16. |
@johncarl81 Doc it. |
Thanks a lot for fixing this, @johncarl81! |
EDIT: please ignore this comment, do what @johncarl81 says in his comment below, i.e.,:
For anyone actually looking to use Parceler with Realm, there's a couple more steps needed:
buildscript {
repositories {
mavenCentral()
}
dependencies {
// replace with the current version of the Android plugin
classpath 'com.android.tools.build:gradle:0.14.4'
// use the latest version, see http://gradleplease.appspot.com/#android-apt
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
|
@vickychijwani, does it work to specify the class type instead of referencing the generated class: |
Yes, it works! Can you explain what causes the error if I call the single parameter version of |
worth noting, another way to handle this is add yoru proxy class to the implementations parameter:
This will add your proxy class to the Parcels wrap mappings. |
I'm trying to use Parceler (1.0.2) and Active Android (3.0.1-SNAPSHOT), but there is something wrong! I have the following code which produces the error: @Table(name = "Playlists")
@Parcel(value = Parcel.Serialization.BEAN, analyze = Playlist.class)
public class Playlist extends Model {
@SerializedName("RemoteId")
@Column(name = "RemoteId")
private int remoreId;
@SerializedName("Token")
@Column(name = "Token", index = true)
private String token = "defaultToken";
@SerializedName("User")
@Column(name = "User", onDelete = Column.ForeignKeyAction.CASCADE)
private User user;
@SerializedName("Name")
@Column(name = "Name")
private String name;
@SerializedName("Create")
@Column(name = "Created")
private long created;
@SerializedName("Updated")
@Column(name = "Updated")
private long updated;
public Playlist() {
super();
}
.... And in the Main.java I have: ...
Parcelable playlistParcelable = Parcels.wrap(playlist);
... I also tried it in this way: ...
Parcelable playlistParcelable = Parcels.wrap(Playlist.class, playlist);
... but still it does not work, someone knows why? |
Can you share your build?
|
Ah, it looks like there's an error during compilation. From your screenshot:
Trying your code out on my test bench, it seems to work properly. What does |
@johncarl81 Same here :( |
@ppamorim, @Makingweb, can you offer any more details around this? |
@johncarl81 I'm working with Realm and I got this error, Do you know if I can change something to make it works? |
@evasquezcr, you'll need to specify what classes Parceler should analyze, to avoid analyzing the @Parcel(implementations = { PersonRealmProxy.class },
value = Parcel.Serialization.BEAN,
analyze = { Person.class })
public class Person extends RealmObject {
// ...
} See https://realm.io/docs/java/latest/#parceler for details. |
HI, |
What do you mean @hunain-liaquat? |
Issue resolved, I didn't find reference to BirthdayRealmProxy.class but found in io.realm package after build successfully compiled once. |
I have the following code which produces the error:
Error:Parceler: Unable to find read/write generator for type io.realm.Realm for io.realm.RealmObject.realm
It was working all fine without
extends RealmObject
, however I want to use Realm to put to database easily. Is there a way to exlcude the RealmObject fields and just use the basic pojo fields for @parcel?The text was updated successfully, but these errors were encountered: