Skip to content
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

No corresponding property found for constructor parameter nodes #38

Closed
tom91136 opened this issue Aug 10, 2014 · 8 comments
Closed

No corresponding property found for constructor parameter nodes #38

tom91136 opened this issue Aug 10, 2014 · 8 comments

Comments

@tom91136
Copy link

I want to make my data immutable so this is what I did:

....
private final HashMap<String, Bundle> nodes;
....

@ParcelConstructor
 NavigationPath(HashMap<String, Bundle> nodes) {
    this.nodes = nodes;
}

 HashMap<String, Bundle> getNodes() {
    return nodes;
}

Notice that the constructor and getter for node is package private.

This exception is thrown when compiling:

NavigationPath.java:40: error: Parceler: No corresponding property found for constructor parameter     nodes
 NavigationPath(HashMap<String, Bundle> nodes) {

If I make the methods/constructors public, then I loose immutability.
Can you make parceler support at least package private visibility?
Butterknife does that without problems so I assume this can be done?

@johncarl81
Copy link
Owner

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)?

@tom91136
Copy link
Author

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?

@johncarl81
Copy link
Owner

Yes, package private should be supported without reflection. Let me investigate a bit...

@tom91136
Copy link
Author

That would be awesome! thanks

@johncarl81
Copy link
Owner

@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?

@tom91136
Copy link
Author

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)

@johncarl81
Copy link
Owner

@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.

@tom91136
Copy link
Author

Works great! thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants