Git Product home page Git Product logo

Comments (8)

johncarl81 avatar johncarl81 commented on August 10, 2024

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.

tom91136 avatar tom91136 commented on August 10, 2024

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.

johncarl81 avatar johncarl81 commented on August 10, 2024

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

from parceler.

tom91136 avatar tom91136 commented on August 10, 2024

That would be awesome! thanks

from parceler.

johncarl81 avatar johncarl81 commented on August 10, 2024

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

tom91136 avatar tom91136 commented on August 10, 2024

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.

johncarl81 avatar johncarl81 commented on August 10, 2024

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

tom91136 avatar tom91136 commented on August 10, 2024

Works great! thanks

from parceler.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.