Comments (9)
Thanks for the feedback @ahem, I'll have to look at your proposal. An error should be given in the example you gave that there is no default empty constructor and you do not have a constructor annotated. In order to get this to work, you will need to annotate the constructor you want to use in the given class, like so:
@Parcel
public class AClass {
String message;
public final String getMessage() { return this.message; }
public void setMessage(String message) { this.message = message; }
@ParcelConstructor
public AClass(String message) {
this.message = message;
}
}
@Parcel
public class ASubClass extends AClass {
int status;
public int getStatus() { return status; }
public void setStatus(int status) { this.status = status; }
@ParcelConstructor
public ASubClass(String message, int status) {
super(message);
this.status = status;
}
}
Is the problem that Parceler is not associating the "message" parameter between the constructor parameter and the super classes' field?
from parceler.
Interestingly AClass
works just fine without the @ParcelConstructor
annotation. It seems that, when there is only one constructor defined on the class, then parceller defaults to that and doesn't require the annotation (at least, that is what I think this bit does: ParcelableAnalysis:258).
But, anyway, as you say, constructor annotation or no constructor annotation, when I add the subclass then the project doesn't compile anymore, and fails with this error:
Parceler: Accessor not found for property message
I can understand that this happens because there is no accessor defined for the message property in ASubClass
, but there is one available in the base class, so I would think parceler would just use that?
from parceler.
Looking at this issue in depth. I can reproduce it and confirm that this not the expected behavior of Paceler.
First, you should be required to annotate the constructor you want to use if a single empty constructor (or default constructor) doesn't exist. Otherwise this should flag an error. Parceler does not automatically decide which constructor is appropriate to use, it needs your direction. The code you highlighted does part of that, it looks for a single empty constructor, the code that flags the error just doesn't exist (yet).
Second, and this is where I would like feedback from you @ahem, associating constructor parameters with properties in the inheritance hierarchy of a bean presents a challenge. At each level of the class hierarchy, Parceler requires the classes' properties (defined by either fields, methods or manually annotated) to be uniquely named. This is easy to enforce because you cannot name a field or method the same thing twice. Constructor parameters must match some reader in the class. This allows Parceler to write the value in the constructor and read it back from a field or method. Right now constructor parameters may only match the same hierarchy level properties. If we were to match on all hierarchy levels, we would need to check for uniqueness across the entire hierarchy. I can see a couple solutions to this:
- All Constructor Parameters must have unique readers across all levels of inheritance.
- Constructor Parameters match the highest hierarchy level property reader, if duplicates exist
I'm starting to lean towards matching the highest level reader because we would not have to do a deep duplicate check.
What are your thoughts on this?
from parceler.
I think that the way constructor parameters are supported now is very easy to understand - it seems very natural that you just have to name the parameter the same as the field or getter function, and then Parceler automatically connects them.
I really would like it if Parceler would match property accessors on other hierarchy levels, though, and I agree with you that the best way to handle duplicated property names would be to use the accessor on the highest level.
from parceler.
I decided to go with option 1 as it's less mysterious and easier to fix when problems come up. I also was able to make your use case pass, with the @ParcelConstructor
parameters added. I've deployed the Parceler SNAPSHOT to maven central under 0.2.8-SNAPSHOT, could you give it a try and let me know if it works for you?
from parceler.
@ahem I'm thinking about cutting a release soon, I'd appreciate your feedback before then.
from parceler.
Closing this issue, feel free to reopen if this fix didn't work.
from parceler.
@johncarl81 Sorry for the delayed feedback - I was on vacation over easter, and internet access turned out to be pretty difficult to find.
Anyways, I have tested you changes and they work perfectly. Thank you very much for the quick response and fix :-)
from parceler.
Fantastic. Thank you for reporting it!
from parceler.
Related Issues (20)
- How to use ParcelClass in multi-module project? HOT 2
- Leak on parceler compiler (org.parceler.ParcelAnnotationProcessor$$Bootstrap) HOT 31
- Parceler: No corresponding property found for constructor boolean parameter HOT 1
- 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
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.