Comments (8)
Parceler supports all modifiers, including package private (FYI, regular-private is discouraged as it uses reflection).
What version are you using? Are you using @Parcel(Parcel.Serialization.METHOD)
or @Parcel(Parcel.Serialization.FIELD)
?
from parceler.
I'm using @Parcel(Serialization.METHOD)
After some testing, constructor works fine but not the getters:
Works:
@ParcelConstructor
NavigationPath(HashMap<String, Bundle> nodes) {
this.nodes = nodes;
}
public HashMap<String, Bundle> getNodes() {
return nodes;
}
Doesn't work:
@ParcelConstructor
NavigationPath(HashMap<String, Bundle> nodes) {
this.nodes = nodes;
}
HashMap<String, Bundle> getNodes() {
return nodes;
}
Can package private be supported without using reflection?
from parceler.
Yes, package private should be supported without reflection. Let me investigate a bit...
from parceler.
That would be awesome! thanks
from parceler.
@tom91136, Finally got to the bottom of this. Are you seeing this NPE also?:
Exception in thread "pool-3-thread-1" java.lang.NullPointerException
at org.parceler.internal.ParcelableGenerator.buildWriteToParcel(ParcelableGenerator.java:286)
at org.parceler.internal.ParcelableGenerator.buildParcelWrite(ParcelableGenerator.java:191)
at org.parceler.internal.ParcelableGenerator.generateParcelable(ParcelableGenerator.java:101)
at org.parceler.internal.ParcelTransactionWorker.innerRun(ParcelTransactionWorker.java:53)
at org.parceler.internal.ParcelTransactionWorker.innerRun(ParcelTransactionWorker.java:34)
at org.parceler.transfuse.transaction.AbstractCompletionTransactionWorker.run(AbstractCompletionTransactionWorker.java:35)
...
Remembering the thoughts behind METHOD
serialization, this feature follows the java bean standard, which specifies that getters and setters must be named a certain way have certain parameters and return types, and be public
.
This is a problem in the library, however. I'm thinking that 1. this should be flagged as an error, because Parceler cannot find a valid getter and 2. Should be overrideable with an annotation, so this should work:
@Parcel(Parcel.Serialization.METHOD)
public class NavigationPath {
private final HashMap<String, Bundle> nodes;
@ParcelConstructor
NavigationPath(HashMap<String, Bundle> nodes) {
this.nodes = nodes;
}
@ParcelProperty("nodes")
HashMap<String, Bundle> getNodes() {
return nodes;
}
}
Thoughts?
from parceler.
Yes that's the exact stacktrace I got
that looks like a pretty good solution to me
also, if a field/method is annotated properly, suppress the warning (or with an annotation like @Suppress)
from parceler.
@tom91136, Both of these cases are implemented and your example should work now with the getNodes()
method annotated with @ParcelProperty("nodes")
. I've deployed this under 0.2.11-SNAPSHOT to Maven central and pushed to 94cb848. Let me know if this works for you.
from parceler.
Works great! thanks
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.