Comments (39)
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 ParcelConverter
that gives you the ability to define serialization manually.
Second, we (@loganj) have discussed adding a scan-limit to the processor which would allow you to tell the processor to stop and not process RealmObject
or deeper. It seems that this would be the use case for such a feature.
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 {
//...
}
from parceler.
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.
from parceler.
Thanks, should it be in the Maven repo? What should i put in my build.girdle instead of
compile 'org.parceler:parceler:0.2.15'
Many thanks
from parceler.
You need to add the maven central snapshots repo:
repositories {
mavenCentral()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots/"
}
}
And update the parceler dependency to:
compile 'org.parceler:parceler-api:0.2.16-SNAPSHOT'
provided 'org.parceler:parceler:0.2.16-SNAPSHOT'
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.
from parceler.
Thanks, i got an error saying:
Error:Could not find org.parceler:parceler-api:0.2.16-SNAPSHOT.
Required by:
TestAndroid:app:unspecified
from parceler.
Thanks, I found my mistake here : http://stackoverflow.com/questions/20574111/add-maven-repository-to-build-gradle
from parceler.
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
from parceler.
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 Serialization.FIELD
technique and it finds private fields. Can you clarify?
from parceler.
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
from parceler.
Oh OK, yes, Serialization.METHOD
will follow the private fields & getter/setter Java Bean standard.
from parceler.
By the way, I think I'm going to change the name of this Serialization technique to Serialization.BEAN
to better represent what standard it follows. Any thoughts on this? (#60)
from parceler.
@somghosh, how did this work out for you?
from parceler.
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
from parceler.
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?
from parceler.
+1, not working with ActiveAndroid too.
from parceler.
@johncarl81 I think that would solve the problem. Many thanks
from parceler.
@somghosh not working with snapshot, analysisLimit doesn't exist.
from parceler.
@ppamorim, I've been working on another branch that I pushed out to maven central. You can still get to this feature by building the limit_analysis
branch on your own (#59).
from parceler.
@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!
from parceler.
@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.
from parceler.
This is implemented and deployed in version 0.2.16.
from parceler.
@johncarl81 Doc it.
from parceler.
Thanks a lot for fixing this, @johncarl81!
from parceler.
EDIT: please ignore this comment, do what @johncarl81 says in his comment below, i.e.,:
- Use
Parcels.wrap(MyObj.class, obj)
instead ofParcels.wrap(obj)
, OR - Annotate your class as
@Parcel(implementations={ MyObjRealmProxy.class })
(this would require you to makeMyObjRealmProxy
visible to the IDE by adding theandroid-apt
plugin as below or adding the generated proxy class manually to your IDE sources)
For anyone actually looking to use Parceler with Realm, there's a couple more steps needed:
- Add the android-apt plugin to your build.gradle, so that the generated
Parcelable
class is visible to Android Studio.
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'
- Use
new MyObj$$Parcelable(obj)
instead ofParcels.wrap(obj)
, otherwise your app will crash withorg.parceler.ParcelerRuntimeException: Unable to create ParcelableFactory for io.realm.MyObjRealmProxy
. You can still useParcels.unwrap(...)
on the other side.
from parceler.
@vickychijwani, does it work to specify the class type instead of referencing the generated class:
Parcels.wrap(Feed.class, obj)
from parceler.
Yes, it works! Can you explain what causes the error if I call the single parameter version of Parcels.wrap(...)
? Thanks!
from parceler.
Parcels.wrap()
looks up your instance against a map of ParcelableFactory
s by calling .getClass()
. The downside of this is it ignores inheritance, so if your class is proxied (like I assume MyObjRealProxy
is), then Parceler doesn't know what to do.
worth noting, another way to handle this is add yoru proxy class to the implementations parameter:
@Parcel(implementations={MyObjRealProxy.class})
This will add your proxy class to the Parcels wrap mappings.
from parceler.
@ppamorim Documented here:
https://github.com/johncarl81/parceler#advanced-configuration
http://parceler.org/#advanced_configuration
from parceler.
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: org.parceler.ParcelerRuntimeException: Unable to find generated Parcelable class for com.mywebsitetest.android.model.Playlist, verify that your class is configured properly and that the Parcelable class com.mywebsitetest.android.model.Playlist$$Parcelable is generated by Parceler.
@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?
from parceler.
from parceler.
Sure!
In the gradle console I also have the follow error:
build.gradle (Module: app)
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.mywebsitetest.android"
minSdkVersion 18
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'it.neokree:MaterialTabs:0.11'
compile 'de.greenrobot:eventbus:2.4.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'
compile "org.parceler:parceler-api:1.0.2"
apt "org.parceler:parceler:1.0.2"
}
build.gradle (Project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
// replace with the current version of the Android plugin
// use the latest version, see http://gradleplease.appspot.com/#android-apt
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
allprojects {
repositories {
jcenter()
}
}
Thanks for your help!
from parceler.
Ah, it looks like there's an error during compilation. From your screenshot:
Unable to find read/write generator for type com.activeandroid.TableInfo for com.activeandroid.Model.mTableInfo
Trying your code out on my test bench, it seems to work properly. What does User
look like? Does User
also extend Model
?
from parceler.
@johncarl81 Same here :(
from parceler.
@ppamorim, @Makingweb, can you offer any more details around this?
from parceler.
@johncarl81 I'm working with Realm and I got this error,
'Error:Parceler: Unable to find read/write generator for type io.realm.Realm for io.realm.RealmObject.realm
Error:Parceler: Unable to find read/write generator for type io.realm.internal.Row for io.realm.RealmObject.row
Error:Parceler: Unable to find read/write generator for type io.realm.Realm for io.realm.RealmObject.realm
Error:Parceler: Unable to find read/write generator for type io.realm.internal.Row for io.realm.RealmObject.row'
Do you know if I can change something to make it works?
from parceler.
@evasquezcr, you'll need to specify what classes Parceler should analyze, to avoid analyzing the RealmObject
base class. People also have had success by specifying the Realm Proxy object in the implementations configuration. Example:
@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.
from parceler.
HI,
How we can have refrence to Proxy class ?
from parceler.
What do you mean @hunain-liaquat?
from parceler.
Issue resolved, I didn't find reference to BirthdayRealmProxy.class but found in io.realm package after build successfully compiled once.
from parceler.
Related Issues (20)
- Ability to treat reflection warnings as errors HOT 5
- Parceler fails when used with with Lifecycle-viewmodel 2.2.0 HOT 7
- Facing Vulnerabilities in parceler library HOT 1
- Facing Vulnerabilities in parceler library HOT 1
- Polymorphism documentation not updated? HOT 6
- Cannot get working with navigation graph HOT 1
- Crashing on background HOT 4
- ParcelAnnotationProcessor.process take lot amount of time. HOT 15
- Unable to find generated Parcelable class HOT 1
- error: Parceler: Code generation did not complete successfully. HOT 47
- Cant find class to parcel ! HOT 1
- Can't generate code HOT 3
- Unable to Marshall with Parceler HOT 2
- Errors in HashMap$$PackageHelper HOT 3
- cannot running with kapt HOT 1
- Parceler: Code generation did not complete successfully. org.parceler.transfuse.transaction.TransactionRuntimeException: Encountered ErrorType <error>, unable to recover HOT 4
- [Request Feature] Support for Kotlin Symbol Processing
- Parceler code generation fails on AS 2023.3.1
- Getters and Setter Alphabetically Order for Write and Read
- Not sure how to convert a Cursor
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from parceler.